Skip to content

Commit

Permalink
Added allowDuplicates property to AutocompleteArrayInput and fix marm…
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagoschenkel committed Feb 7, 2019
1 parent 925408c commit 410943a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/ra-ui-materialui/src/input/AutocompleteArrayInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,18 @@ export class AutocompleteArrayInput extends React.Component {
};

handleSuggestionSelected = (event, { suggestion, method }) => {
const { input } = this.props;
const { allowDuplicates, input } = this.props;

const values = this.state.inputValue || [];
const newValue = this.getSuggestionValue(suggestion);

if (allowDuplicates || values.indexOf(newValue) < 0) {
// Add selected value to the list
input.onChange([...values, newValue]);

input.onChange([
...(this.state.inputValue || []),
this.getSuggestionValue(suggestion),
]);
// Ensure to reset the filter
this.updateFilter('');
}

if (method === 'enter') {
event.preventDefault();
Expand Down Expand Up @@ -487,6 +493,7 @@ export class AutocompleteArrayInput extends React.Component {
}

AutocompleteArrayInput.propTypes = {
allowDuplicates: PropTypes.bool,
allowEmpty: PropTypes.bool,
alwaysRenderSuggestions: PropTypes.bool, // used only for unit tests
choices: PropTypes.arrayOf(PropTypes.object),
Expand All @@ -513,6 +520,7 @@ AutocompleteArrayInput.propTypes = {
};

AutocompleteArrayInput.defaultProps = {
allowDuplicates: true,
choices: [],
options: {},
optionText: 'name',
Expand Down

0 comments on commit 410943a

Please sign in to comment.