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)?
Probably linked to https://github.com/TeamWertarbyte/material-ui-chip-input/issues/231. We don't pass allowDuplicates so it should defaults to false
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:
https://github.com/tiagoschenkel/react-admin/commit/410943a7930f3db182747fff007bee92a0ea1064
Any news about this issue? Ability to select duplicate values looks really ugly.
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();
}
}
};
I'm still waiting for a feedback on this merge request:
https://github.com/marmelab/react-admin/pull/2912
@djhi, could you please take a look and tell us what is missing?
Fixed by #4026
Most helpful comment
I'm still waiting for a feedback on this merge request:
https://github.com/marmelab/react-admin/pull/2912
@djhi, could you please take a look and tell us what is missing?