make allowEmpty compatible with multiple on SelectButton
parent
e53d48ed62
commit
b88f80b0f5
|
@ -8,7 +8,7 @@
|
||||||
:disabled="disabled || isOptionDisabled(option)"
|
:disabled="disabled || isOptionDisabled(option)"
|
||||||
:unstyled="unstyled"
|
:unstyled="unstyled"
|
||||||
:size="size"
|
:size="size"
|
||||||
:readonly="!allowEmpty && isSelected(option)"
|
:readonly="isOptionReadonly(option)"
|
||||||
@change="onOptionSelect($event, option, index)"
|
@change="onOptionSelect($event, option, index)"
|
||||||
:pt="ptm('pcToggleButton')"
|
:pt="ptm('pcToggleButton')"
|
||||||
>
|
>
|
||||||
|
@ -46,24 +46,34 @@ export default {
|
||||||
isOptionDisabled(option) {
|
isOptionDisabled(option) {
|
||||||
return this.optionDisabled ? resolveFieldData(option, this.optionDisabled) : false;
|
return this.optionDisabled ? resolveFieldData(option, this.optionDisabled) : false;
|
||||||
},
|
},
|
||||||
|
isOptionReadonly(option) {
|
||||||
|
if (this.allowEmpty) return false;
|
||||||
|
|
||||||
|
let selected = this.isSelected(option);
|
||||||
|
|
||||||
|
if (this.multiple) {
|
||||||
|
return selected && this.d_value.length === 1;
|
||||||
|
} else {
|
||||||
|
return selected;
|
||||||
|
}
|
||||||
|
},
|
||||||
onOptionSelect(event, option, index) {
|
onOptionSelect(event, option, index) {
|
||||||
if (this.disabled || this.isOptionDisabled(option)) {
|
if (this.disabled || this.isOptionDisabled(option) || this.isOptionReadonly(option)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let selected = this.isSelected(option);
|
let selected = this.isSelected(option);
|
||||||
|
|
||||||
if (selected && !this.allowEmpty) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let optionValue = this.getOptionValue(option);
|
let optionValue = this.getOptionValue(option);
|
||||||
let newValue;
|
let newValue;
|
||||||
|
|
||||||
if (this.multiple) {
|
if (this.multiple) {
|
||||||
if (selected) newValue = this.d_value.filter((val) => !equals(val, optionValue, this.equalityKey));
|
if (selected) {
|
||||||
else newValue = this.d_value ? [...this.d_value, optionValue] : [optionValue];
|
newValue = this.d_value.filter((val) => !equals(val, optionValue, this.equalityKey));
|
||||||
|
if (!this.allowEmpty && newValue.length === 0) return;
|
||||||
|
} else newValue = this.d_value ? [...this.d_value, optionValue] : [optionValue];
|
||||||
} else {
|
} else {
|
||||||
|
if (selected && !this.allowEmpty) return;
|
||||||
newValue = selected ? null : optionValue;
|
newValue = selected ? null : optionValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue