Skip to content

Commit

Permalink
Fixed #90 - optionValue and dataKey combination is broken is Select C…
Browse files Browse the repository at this point in the history
…omponents
  • Loading branch information
cagataycivici committed Jan 21, 2020
1 parent d2b278c commit e590e10
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
9 changes: 6 additions & 3 deletions src/components/dropdown/Dropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default {
if (this.value != null && this.options) {
for (let option of this.options) {
if ((ObjectUtils.equals(this.value, this.getOptionValue(option), this.dataKey))) {
if ((ObjectUtils.equals(this.value, this.getOptionValue(option), this.equalityKey))) {
selectedOption = option;
break;
}
Expand All @@ -107,14 +107,14 @@ export default {
return selectedOption;
},
isSelected(option) {
return ObjectUtils.equals(this.value, this.getOptionValue(option), this.dataKey);
return ObjectUtils.equals(this.value, this.getOptionValue(option), this.equalityKey);
},
getSelectedOptionIndex() {
let selectedOptionIndex = -1;
if (this.value != null && this.visibleOptions) {
for (let i = 0; i < this.visibleOptions.length; i++) {
if ((ObjectUtils.equals(this.value, this.getOptionValue(this.visibleOptions[i]), this.dataKey))) {
if ((ObjectUtils.equals(this.value, this.getOptionValue(this.visibleOptions[i]), this.equalityKey))) {
selectedOptionIndex = i;
break;
}
Expand Down Expand Up @@ -420,6 +420,9 @@ export default {
return this.getOptionLabel(selectedOption);
else
return this.value;
},
equalityKey() {
return this.optionValue ? null : this.dataKey;
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/components/listbox/Listbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,21 @@ export default {
if (this.multiple) {
if (this.value) {
for (let val of this.value) {
if (ObjectUtils.equals(val, optionValue, this.dataKey)) {
if (ObjectUtils.equals(val, optionValue, this.equalityKey)) {
selected = true;
break;
}
}
}
}
else {
selected = ObjectUtils.equals(this.value, optionValue, this.dataKey);
selected = ObjectUtils.equals(this.value, optionValue, this.equalityKey);
}
return selected;
},
removeOption(option) {
return this.value.filter(val => !ObjectUtils.equals(val, this.getOptionValue(option), this.dataKey));
return this.value.filter(val => !ObjectUtils.equals(val, this.getOptionValue(option), this.equalityKey));
},
updateModel(event, value) {
this.$emit('input', value);
Expand Down Expand Up @@ -218,6 +218,9 @@ export default {
return this.options.filter(option => this.getOptionLabel(option).toLowerCase().indexOf(this.filterValue.toLowerCase()) > -1);
else
return this.options;
},
equalityKey() {
return this.optionValue ? null : this.dataKey;
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/components/multiselect/MultiSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default {
if (this.value) {
for (let val of this.value) {
if (ObjectUtils.equals(val, optionValue, this.dataKey)) {
if (ObjectUtils.equals(val, optionValue, this.equalityKey)) {
selected = true;
break;
}
Expand Down Expand Up @@ -183,7 +183,7 @@ export default {
let value = null;
if (selected)
value = this.value.filter(val => !ObjectUtils.equals(val, this.getOptionValue(option), this.dataKey));
value = this.value.filter(val => !ObjectUtils.equals(val, this.getOptionValue(option), this.equalityKey));
else
value = [...this.value || [], this.getOptionValue(option)];
Expand Down Expand Up @@ -276,7 +276,7 @@ export default {
for (let option of this.options) {
let optionValue = this.getOptionValue(option);
if(ObjectUtils.equals(optionValue, val, this.dataKey)) {
if(ObjectUtils.equals(optionValue, val, this.equalityKey)) {
label = this.getOptionLabel(option);
break;
}
Expand Down Expand Up @@ -354,6 +354,9 @@ export default {
else {
return this.value && this.options && (this.value.length > 0 && this.value.length === this.options.length);
}
},
equalityKey() {
return this.optionValue ? null : this.dataKey;
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/components/selectbutton/SelectButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default {
if(this.multiple) {
if (selected)
newValue = this.value.filter(val => !ObjectUtils.equals(val, optionValue, this.dataKey));
newValue = this.value.filter(val => !ObjectUtils.equals(val, optionValue, this.equalityKey));
else
newValue = this.value ? [...this.value, optionValue]: [optionValue];
}
Expand All @@ -69,15 +69,15 @@ export default {
if (this.multiple) {
if (this.value) {
for (let val of this.value) {
if (ObjectUtils.equals(val, optionValue, this.dataKey)) {
if (ObjectUtils.equals(val, optionValue, this.equalityKey)) {
selected = true;
break;
}
}
}
}
else {
selected = ObjectUtils.equals(this.value, optionValue, this.dataKey);
selected = ObjectUtils.equals(this.value, optionValue, this.equalityKey);
}
return selected;
Expand All @@ -94,7 +94,10 @@ export default {
computed: {
containerClass() {
return 'p-selectbutton p-buttonset p-component p-buttonset-' + String(this.options ? this.options.length : 0);
}
},
},
equalityKey() {
return this.optionValue ? null : this.dataKey;
}
}
}
</script>

0 comments on commit e590e10

Please sign in to comment.