From e590e10258ef52fee6338e9ad0aab52d088a3682 Mon Sep 17 00:00:00 2001 From: cagataycivici Date: Tue, 21 Jan 2020 09:53:46 +0300 Subject: [PATCH] Fixed #90 - optionValue and dataKey combination is broken is Select Components --- src/components/dropdown/Dropdown.vue | 9 ++++++--- src/components/listbox/Listbox.vue | 9 ++++++--- src/components/multiselect/MultiSelect.vue | 9 ++++++--- src/components/selectbutton/SelectButton.vue | 13 ++++++++----- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/components/dropdown/Dropdown.vue b/src/components/dropdown/Dropdown.vue index aadde1e54..c45efc7e7 100644 --- a/src/components/dropdown/Dropdown.vue +++ b/src/components/dropdown/Dropdown.vue @@ -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; } @@ -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; } @@ -420,6 +420,9 @@ export default { return this.getOptionLabel(selectedOption); else return this.value; + }, + equalityKey() { + return this.optionValue ? null : this.dataKey; } } } diff --git a/src/components/listbox/Listbox.vue b/src/components/listbox/Listbox.vue index b98442b99..16b2da664 100644 --- a/src/components/listbox/Listbox.vue +++ b/src/components/listbox/Listbox.vue @@ -144,7 +144,7 @@ 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; } @@ -152,13 +152,13 @@ export default { } } 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); @@ -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; } } } diff --git a/src/components/multiselect/MultiSelect.vue b/src/components/multiselect/MultiSelect.vue index 522fa3180..a14e6d953 100644 --- a/src/components/multiselect/MultiSelect.vue +++ b/src/components/multiselect/MultiSelect.vue @@ -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; } @@ -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)]; @@ -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; } @@ -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; } } } diff --git a/src/components/selectbutton/SelectButton.vue b/src/components/selectbutton/SelectButton.vue index 0a958c203..1937f0fb3 100644 --- a/src/components/selectbutton/SelectButton.vue +++ b/src/components/selectbutton/SelectButton.vue @@ -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]; } @@ -69,7 +69,7 @@ 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; } @@ -77,7 +77,7 @@ export default { } } else { - selected = ObjectUtils.equals(this.value, optionValue, this.dataKey); + selected = ObjectUtils.equals(this.value, optionValue, this.equalityKey); } return selected; @@ -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; + } + } } \ No newline at end of file