Skip to content

Commit

Permalink
Fixed #2011 - MultiSelect is not working nested value option
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed May 5, 2021
1 parent 6da1d73 commit 3c1988a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/components/multiselect/MultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,12 @@ export class MultiSelect extends Component {
}

let optionValue = this.getOptionValue(option);
let isOptionValueUsed = this.isOptionValueUsed(option);
let selected = this.isSelected(option);
let allowOptionSelect = this.allowOptionSelect();

if (selected)
this.updateModel(originalEvent, this.props.value.filter(val => !ObjectUtils.equals(this.getOptionValue(val), optionValue, this.equalityKey())));
this.updateModel(originalEvent, this.props.value.filter(val => !ObjectUtils.equals(isOptionValueUsed ? val : this.getOptionValue(val), optionValue, this.equalityKey())));
else if (allowOptionSelect)
this.updateModel(originalEvent, [...this.props.value || [], optionValue]);
}
Expand Down Expand Up @@ -306,7 +307,7 @@ export class MultiSelect extends Component {

if (this.props.optionGroupLabel) {
value = [];
visibleOptions.forEach(optionGroup => value = [...value, ...this.getOptionGroupChildren(optionGroup).filter((option) => !this.isOptionDisabled(option))]);
visibleOptions.forEach(optionGroup => value = [...value, ...this.getOptionGroupChildren(optionGroup).filter((option) => !this.isOptionDisabled(option)).map(option => this.getOptionValue(option))]);
}
else {
value = visibleOptions.map(option => this.getOptionValue(option));
Expand Down Expand Up @@ -403,9 +404,10 @@ export class MultiSelect extends Component {

if (this.props.value) {
let optionValue = this.getOptionValue(option);
let isOptionValueUsed = this.isOptionValueUsed(option);
let key = this.equalityKey();

selected = this.props.value.some(val => ObjectUtils.equals(this.getOptionValue(val), optionValue, key));
selected = this.props.value.some(val => ObjectUtils.equals(isOptionValueUsed ? val : this.getOptionValue(val), optionValue, key));
}

return selected;
Expand Down Expand Up @@ -647,6 +649,10 @@ export class MultiSelect extends Component {
return (option && option['disabled'] !== undefined ? option['disabled'] : false);
}

isOptionValueUsed(option) {
return !this.props.optionValue && option && option['value'] !== undefined;
}

getVisibleOptions() {
if (this.hasFilter()) {
let filterValue = this.state.filter.trim().toLocaleLowerCase(this.props.filterLocale);
Expand Down

0 comments on commit 3c1988a

Please sign in to comment.