reset query if options are removed

This commit is contained in:
Sergio Crisostomo 2018-04-13 10:54:31 +02:00
parent 45bcc14daa
commit b6c069ca9d

View file

@ -282,10 +282,11 @@
const selectedValues = this.values.map(({value}) => value); const selectedValues = this.values.map(({value}) => value);
for (let option of (this.slotOptions || [])) { for (let option of (this.slotOptions || [])) {
if (!option.componentOptions) continue; const cOptions = option.componentOptions;
if (!cOptions) continue;
if (option.componentOptions.tag.match(optionGroupRegexp)){ if (cOptions.tag.match(optionGroupRegexp)){
let children = option.componentOptions.children; let children = cOptions.children;
// remove filtered children // remove filtered children
if (this.filterable){ if (this.filterable){
@ -294,16 +295,16 @@
); );
} }
option.componentOptions.children = children.map(opt => { cOptions.children = children.map(opt => {
optionCounter = optionCounter + 1; optionCounter = optionCounter + 1;
return this.processOption(opt, selectedValues, optionCounter === currentIndex); return this.processOption(opt, selectedValues, optionCounter === currentIndex);
}); });
// keep the group if it still has children // keep the group if it still has children
if (option.componentOptions.children.length > 0) selectOptions.push({...option}); if (cOptions.children.length > 0) selectOptions.push({...option});
} else { } else {
// ignore option if not passing filter // ignore option if not passing filter
const optionPassesFilter = this.filterable ? this.validateOption(option.componentOptions) : option; const optionPassesFilter = this.filterable ? this.validateOption(cOptions) : option;
if (!optionPassesFilter) continue; if (!optionPassesFilter) continue;
optionCounter = optionCounter + 1; optionCounter = optionCounter + 1;
@ -614,11 +615,15 @@
dropVisible(open){ dropVisible(open){
this.broadcast('Drop', open ? 'on-update-popper' : 'on-destroy-popper'); this.broadcast('Drop', open ? 'on-update-popper' : 'on-destroy-popper');
}, },
selectOptions(){ selectOptions(options){
if (this.hasExpectedValue){ if (this.hasExpectedValue){
this.values = this.values.map(this.getOptionData); this.values = this.values.map(this.getOptionData);
this.hasExpectedValue = false; this.hasExpectedValue = false;
} }
if (options.length === 0){
this.query = '';
}
} }
} }
}; };