From 7f63e58ced806a28e730483ab8dfa26ebce0057b Mon Sep 17 00:00:00 2001 From: Sergio Crisostomo Date: Thu, 12 Apr 2018 16:32:35 +0200 Subject: [PATCH] Make possible for v-model to wait for async options --- src/components/select/select.vue | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/select/select.vue b/src/components/select/select.vue index 1584f80..25d92bc 100644 --- a/src/components/select/select.vue +++ b/src/components/select/select.vue @@ -179,9 +179,13 @@ this.$on('on-select-selected', this.onOptionClick); // set the initial values if there are any - if (this.values.length > 0 && !this.remote){ + if (this.values.length > 0 && !this.remote && this.selectOptions.length > 0){ this.values = this.values.map(this.getOptionData); } + + if (this.values.length > 0 && this.selectOptions.length === 0){ + this.hasExpectedValue = this.values; + } }, data () { @@ -198,6 +202,7 @@ slotOptions: this.$slots.default, caretPosition: -1, lastRemoteQuery: '', + hasExpectedValue: false, }; }, computed: { @@ -337,7 +342,7 @@ }, getOptionData(value){ const option = this.flatOptions.find(({componentOptions}) => componentOptions.propsData.value === value); - if (!option) return {}; + if (!option) return null; const textContent = option.componentOptions.children.reduce((str, child) => str + (child.text || ''), ''); const label = option.componentOptions.propsData.label || textContent || ''; return { @@ -603,6 +608,12 @@ }, dropVisible(open){ this.broadcast('Drop', open ? 'on-update-popper' : 'on-destroy-popper'); + }, + selectOptions(){ + if (this.hasExpectedValue){ + this.values = this.values.map(this.getOptionData); + this.hasExpectedValue = false; + } } } }; -- libgit2 0.21.4