Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutocompleteArrayInput allows to pick repeated values (probably a feature?) #2311

Closed
aserrallerios opened this issue Sep 12, 2018 · 6 comments

Comments

@aserrallerios
Copy link

import { AutocompleteArrayInput } from 'react-admin';

<AutocompleteArrayInput source="category" choices={[
    { id: 'programming', name: 'Programming' },
    { id: 'lifestyle', name: 'Lifestyle' },
    { id: 'photography', name: 'Photography' },
]} />

Just use the example component. It allows to pick the same value twice. If you remove one of the repeated values, all of them are removed, so it looks like it probably doesn't make sense to allow repeated values (bug).

If it does make sense, there should be an attribute to control whether we want repeated values or not (feature)?

@djhi
Copy link
Collaborator

djhi commented Sep 14, 2018

Probably linked to TeamWertarbyte/material-ui-chip-input#231. We don't pass allowDuplicates so it should defaults to false

tiagoschenkel added a commit to tiagoschenkel/react-admin that referenced this issue Feb 7, 2019
@tiagoschenkel
Copy link
Contributor

The method handleSuggestionSelected is adding the new value directly to the input through onChange method. Even when the property allowDuplicates is enabled in the AutocompleteArrayInputChip this element is added.

A possible solution will be to add a new property to AutocompleteArrayInput component, named allowDuplicates, then check for this property before calling the input.onChange method.

Here is my implementation, let me know if is fine for a merge request:
tiagoschenkel@410943a

@Gorett
Copy link

Gorett commented Jul 11, 2019

Any news about this issue? Ability to select duplicate values looks really ugly.

@Gorett
Copy link

Gorett commented Jul 11, 2019

Whatever, there is a solution how to unable adding of already selected values.

const onChange = data => {
	const arr = Object.values(data);
	if (arr.length > 2) {
		arr.pop();
		const value = arr.pop();
		if (value && arr.includes(value)) {
			data.preventDefault();
		}
	}
};

@tiagoschenkel
Copy link
Contributor

I'm still waiting for a feedback on this merge request:
#2912

@djhi, could you please take a look and tell us what is missing?

@fzaninotto
Copy link
Member

Fixed by #4026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants