Clean up empty/null entries

This commit is contained in:
Sergio Crisostomo 2018-05-08 11:15:49 +02:00
parent 7d14e70c6e
commit 220161f5ed

View file

@ -207,7 +207,7 @@
// set the initial values if there are any // set the initial values if there are any
if (this.values.length > 0 && !this.remote && this.selectOptions.length > 0){ if (this.values.length > 0 && !this.remote && this.selectOptions.length > 0){
this.values = this.values.map(this.getOptionData); this.values = this.values.map(this.getOptionData).filter(Boolean);
} }
if (this.values.length > 0 && this.selectOptions.length === 0){ if (this.values.length > 0 && this.selectOptions.length === 0){
@ -307,7 +307,7 @@
const slotOptions = (this.slotOptions || []); const slotOptions = (this.slotOptions || []);
let optionCounter = -1; let optionCounter = -1;
const currentIndex = this.focusIndex; const currentIndex = this.focusIndex;
const selectedValues = this.values.map(({value}) => value); const selectedValues = this.values.filter(Boolean).map(({value}) => value);
if (this.autoComplete) { if (this.autoComplete) {
const copyChildren = (node, fn) => { const copyChildren = (node, fn) => {
return { return {
@ -398,7 +398,7 @@
const {multiple, value} = this; const {multiple, value} = this;
let initialValue = Array.isArray(value) ? value : [value]; let initialValue = Array.isArray(value) ? value : [value];
if (!multiple && (typeof initialValue[0] === 'undefined' || String(initialValue[0]).trim() === '')) initialValue = []; if (!multiple && (typeof initialValue[0] === 'undefined' || String(initialValue[0]).trim() === '')) initialValue = [];
return initialValue; return initialValue.filter(Boolean);
}, },
processOption(option, values, isFocused){ processOption(option, values, isFocused){
if (!option.componentOptions) return option; if (!option.componentOptions) return option;
@ -580,7 +580,7 @@
if (value === '') this.values = []; if (value === '') this.values = [];
else if (JSON.stringify(value) !== JSON.stringify(publicValue)) { else if (JSON.stringify(value) !== JSON.stringify(publicValue)) {
this.$nextTick(() => this.values = getInitialValue().map(getOptionData)); this.$nextTick(() => this.values = getInitialValue().map(getOptionData).filter(Boolean));
} }
}, },
values(now, before){ values(now, before){
@ -659,7 +659,7 @@
}, },
selectOptions(){ selectOptions(){
if (this.hasExpectedValue){ if (this.hasExpectedValue){
this.values = this.values.map(this.getOptionData); this.values = this.values.map(this.getOptionData).filter(Boolean);
this.hasExpectedValue = false; this.hasExpectedValue = false;
} }