Fixed #90 - optionValue and dataKey combination is broken is Select Components

pull/160/head
cagataycivici 2020-01-21 09:53:46 +03:00
parent d2b278ce0a
commit e590e10258
4 changed files with 26 additions and 14 deletions

View File

@ -97,7 +97,7 @@ export default {
if (this.value != null && this.options) { if (this.value != null && this.options) {
for (let option of 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; selectedOption = option;
break; break;
} }
@ -107,14 +107,14 @@ export default {
return selectedOption; return selectedOption;
}, },
isSelected(option) { isSelected(option) {
return ObjectUtils.equals(this.value, this.getOptionValue(option), this.dataKey); return ObjectUtils.equals(this.value, this.getOptionValue(option), this.equalityKey);
}, },
getSelectedOptionIndex() { getSelectedOptionIndex() {
let selectedOptionIndex = -1; let selectedOptionIndex = -1;
if (this.value != null && this.visibleOptions) { if (this.value != null && this.visibleOptions) {
for (let i = 0; i < this.visibleOptions.length; i++) { 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; selectedOptionIndex = i;
break; break;
} }
@ -420,6 +420,9 @@ export default {
return this.getOptionLabel(selectedOption); return this.getOptionLabel(selectedOption);
else else
return this.value; return this.value;
},
equalityKey() {
return this.optionValue ? null : this.dataKey;
} }
} }
} }

View File

@ -144,7 +144,7 @@ export default {
if (this.multiple) { if (this.multiple) {
if (this.value) { if (this.value) {
for (let val of this.value) { for (let val of this.value) {
if (ObjectUtils.equals(val, optionValue, this.dataKey)) { if (ObjectUtils.equals(val, optionValue, this.equalityKey)) {
selected = true; selected = true;
break; break;
} }
@ -152,13 +152,13 @@ export default {
} }
} }
else { else {
selected = ObjectUtils.equals(this.value, optionValue, this.dataKey); selected = ObjectUtils.equals(this.value, optionValue, this.equalityKey);
} }
return selected; return selected;
}, },
removeOption(option) { 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) { updateModel(event, value) {
this.$emit('input', 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); return this.options.filter(option => this.getOptionLabel(option).toLowerCase().indexOf(this.filterValue.toLowerCase()) > -1);
else else
return this.options; return this.options;
},
equalityKey() {
return this.optionValue ? null : this.dataKey;
} }
} }
} }

View File

@ -109,7 +109,7 @@ export default {
if (this.value) { if (this.value) {
for (let val of this.value) { for (let val of this.value) {
if (ObjectUtils.equals(val, optionValue, this.dataKey)) { if (ObjectUtils.equals(val, optionValue, this.equalityKey)) {
selected = true; selected = true;
break; break;
} }
@ -183,7 +183,7 @@ export default {
let value = null; let value = null;
if (selected) 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 else
value = [...this.value || [], this.getOptionValue(option)]; value = [...this.value || [], this.getOptionValue(option)];
@ -276,7 +276,7 @@ export default {
for (let option of this.options) { for (let option of this.options) {
let optionValue = this.getOptionValue(option); let optionValue = this.getOptionValue(option);
if(ObjectUtils.equals(optionValue, val, this.dataKey)) { if(ObjectUtils.equals(optionValue, val, this.equalityKey)) {
label = this.getOptionLabel(option); label = this.getOptionLabel(option);
break; break;
} }
@ -354,6 +354,9 @@ export default {
else { else {
return this.value && this.options && (this.value.length > 0 && this.value.length === this.options.length); return this.value && this.options && (this.value.length > 0 && this.value.length === this.options.length);
} }
},
equalityKey() {
return this.optionValue ? null : this.dataKey;
} }
} }
} }

View File

@ -52,7 +52,7 @@ export default {
if(this.multiple) { if(this.multiple) {
if (selected) 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 else
newValue = this.value ? [...this.value, optionValue]: [optionValue]; newValue = this.value ? [...this.value, optionValue]: [optionValue];
} }
@ -69,7 +69,7 @@ export default {
if (this.multiple) { if (this.multiple) {
if (this.value) { if (this.value) {
for (let val of this.value) { for (let val of this.value) {
if (ObjectUtils.equals(val, optionValue, this.dataKey)) { if (ObjectUtils.equals(val, optionValue, this.equalityKey)) {
selected = true; selected = true;
break; break;
} }
@ -77,7 +77,7 @@ export default {
} }
} }
else { else {
selected = ObjectUtils.equals(this.value, optionValue, this.dataKey); selected = ObjectUtils.equals(this.value, optionValue, this.equalityKey);
} }
return selected; return selected;
@ -94,7 +94,10 @@ export default {
computed: { computed: {
containerClass() { containerClass() {
return 'p-selectbutton p-buttonset p-component p-buttonset-' + String(this.options ? this.options.length : 0); return 'p-selectbutton p-buttonset p-component p-buttonset-' + String(this.options ? this.options.length : 0);
}
}, },
equalityKey() {
return this.optionValue ? null : this.dataKey;
}
}
} }
</script> </script>