fix Select bug when use label-in-value, filterable and multiple

This commit is contained in:
梁灏 2021-05-24 16:07:16 +08:00
parent 03e6c07622
commit f13f6f6408

View file

@ -417,11 +417,13 @@
return selectOptions && selectOptions.length === 0 && (!remote || (remote && !loading));
},
publicValue(){
if (this.labelInValue){
return this.multiple ? this.values : this.values[0];
} else {
return this.multiple ? this.values.map(option => option.value) : (this.values[0] || {}).value;
}
// labelInValue bug:Selectlabel-in-value
// if (this.labelInValue){
// return this.multiple ? this.values : this.values[0];
// } else {
// return this.multiple ? this.values.map(option => option.value) : (this.values[0] || {}).value;
// }
return this.multiple ? this.values.map(option => option.value) : (this.values[0] || {}).value;
},
canBeCleared(){
const uiStateMatch = this.hasMouseHoverHead || this.active;
@ -817,14 +819,24 @@
const newValue = JSON.stringify(now);
const oldValue = JSON.stringify(before);
// v-model is always just the value, event with labelInValue === true
const vModelValue = (this.publicValue && this.labelInValue) ?
(this.multiple ? this.publicValue.map(({value}) => value) : this.publicValue.value) :
this.publicValue;
// const vModelValue = (this.publicValue && this.labelInValue === false) ?
// (this.multiple ? this.publicValue.map(({value}) => value) : this.publicValue.value) :
// this.publicValue;
// labelInValue emit
const vModelValue = this.publicValue;
const shouldEmitInput = newValue !== oldValue && vModelValue !== this.value;
if (shouldEmitInput) {
let emitValue = this.publicValue;
if (this.labelInValue) {
if (this.multiple) {
emitValue = this.values;
} else {
emitValue = this.values[0];
}
}
this.$emit('input', vModelValue); // to update v-model
this.$emit('on-change', this.publicValue);
this.dispatch('FormItem', 'on-form-change', this.publicValue);
this.$emit('on-change', JSON.stringify(emitValue));
this.dispatch('FormItem', 'on-form-change', JSON.stringify(emitValue));
}
},
query (query) {