diff --git "a/mendix-AutocompleteMultiselect - Verkn\303\274pfung.lnk" "b/mendix-AutocompleteMultiselect - Verkn\303\274pfung.lnk" new file mode 100644 index 0000000..fcf864b Binary files /dev/null and "b/mendix-AutocompleteMultiselect - Verkn\303\274pfung.lnk" differ diff --git a/src/AutocompleteMultiselect.jsx b/src/AutocompleteMultiselect.jsx index ee65410..e04f838 100644 --- a/src/AutocompleteMultiselect.jsx +++ b/src/AutocompleteMultiselect.jsx @@ -66,17 +66,17 @@ export default class AutocompleteMultiselect extends Component { ? this.optionsSelected : this.optionsSelected === null ? [] : [this.optionsSelected]; const optionsSelectedNotInList = optionsSelectedAsArray.filter(selectedOption => { - return dataParsed.find(option => option.title === selectedOption.title && option.key === selectedOption.key) === undefined; + return dataParsed.find(option => ((option.key !== undefined && option.key.length > 0) || option.title === selectedOption.title) && option.key === selectedOption.key) === undefined; }); dataParsed = dataParsed.concat(optionsSelectedNotInList); } else { if (this.props.multiple) { // Else check if optionSelected are still available. This is done since it can be the case that the options have been changed. this.optionsSelected = this.optionsSelected.filter(selectedOption => { - return dataParsed.find(option => option.title === selectedOption.title && option.key === selectedOption.key) !== undefined; + return dataParsed.find(option => ((option.key !== undefined && option.key.length > 0) || option.title === selectedOption.title) && option.key === selectedOption.key) !== undefined; }); } else if (this.optionsSelected !== null) { - this.optionsSelected = dataParsed.find(option => option.title === this.optionsSelected.title && option.key === this.optionsSelected.key); + this.optionsSelected = dataParsed.find(option => ((option.key !== undefined && option.key.length > 0) || option.title === this.optionsSelected.title) && option.key === this.optionsSelected.key); } if (this.optionsSelected === undefined) { this.optionsSelected = null; } @@ -149,7 +149,7 @@ export default class AutocompleteMultiselect extends Component { } else { // Else check if option is selected (based on the title). This is done since it can be the case that the options have been changed. if (multiSelect) { - if (this.optionsSelected.find(option => option.title === optionTitle)) { + if (this.optionsSelected.find(findoption => ((findoption.key !== undefined && option.key.length > 0) || findoption.title === optionTitle) && findoption.key === option.key)) { optionsSelected.push(option); } } else if (this.optionsSelected !== null) { diff --git a/src/components/AutocompleteUI.jsx b/src/components/AutocompleteUI.jsx index 37df501..b8ba1f3 100644 --- a/src/components/AutocompleteUI.jsx +++ b/src/components/AutocompleteUI.jsx @@ -23,7 +23,7 @@ export class AutocompleteUI extends Component { loading = {this.props.loading} loadingText = {this.props.loadingText} onInputChange={ this.props.onInputChange} - getOptionSelected={(option, value) => option.title === value.title && option.key === value.key} + getOptionSelected={(option, value) => ((option.key !== undefined && option.key.length > 0) || option.title === value.title) && option.key === value.key} renderOption={(option, { selected }) => ( {this.props.showCheckboxes ?