Commit 7f63e58ced806a28e730483ab8dfa26ebce0057b
1 parent
cf753854
Make possible for v-model to wait for async options
Showing
1 changed file
with
13 additions
and
2 deletions
Show diff stats
src/components/select/select.vue
| @@ -179,9 +179,13 @@ | @@ -179,9 +179,13 @@ | ||
| 179 | this.$on('on-select-selected', this.onOptionClick); | 179 | this.$on('on-select-selected', this.onOptionClick); |
| 180 | 180 | ||
| 181 | // set the initial values if there are any | 181 | // set the initial values if there are any |
| 182 | - if (this.values.length > 0 && !this.remote){ | 182 | + if (this.values.length > 0 && !this.remote && this.selectOptions.length > 0){ |
| 183 | this.values = this.values.map(this.getOptionData); | 183 | this.values = this.values.map(this.getOptionData); |
| 184 | } | 184 | } |
| 185 | + | ||
| 186 | + if (this.values.length > 0 && this.selectOptions.length === 0){ | ||
| 187 | + this.hasExpectedValue = this.values; | ||
| 188 | + } | ||
| 185 | }, | 189 | }, |
| 186 | data () { | 190 | data () { |
| 187 | 191 | ||
| @@ -198,6 +202,7 @@ | @@ -198,6 +202,7 @@ | ||
| 198 | slotOptions: this.$slots.default, | 202 | slotOptions: this.$slots.default, |
| 199 | caretPosition: -1, | 203 | caretPosition: -1, |
| 200 | lastRemoteQuery: '', | 204 | lastRemoteQuery: '', |
| 205 | + hasExpectedValue: false, | ||
| 201 | }; | 206 | }; |
| 202 | }, | 207 | }, |
| 203 | computed: { | 208 | computed: { |
| @@ -337,7 +342,7 @@ | @@ -337,7 +342,7 @@ | ||
| 337 | }, | 342 | }, |
| 338 | getOptionData(value){ | 343 | getOptionData(value){ |
| 339 | const option = this.flatOptions.find(({componentOptions}) => componentOptions.propsData.value === value); | 344 | const option = this.flatOptions.find(({componentOptions}) => componentOptions.propsData.value === value); |
| 340 | - if (!option) return {}; | 345 | + if (!option) return null; |
| 341 | const textContent = option.componentOptions.children.reduce((str, child) => str + (child.text || ''), ''); | 346 | const textContent = option.componentOptions.children.reduce((str, child) => str + (child.text || ''), ''); |
| 342 | const label = option.componentOptions.propsData.label || textContent || ''; | 347 | const label = option.componentOptions.propsData.label || textContent || ''; |
| 343 | return { | 348 | return { |
| @@ -603,6 +608,12 @@ | @@ -603,6 +608,12 @@ | ||
| 603 | }, | 608 | }, |
| 604 | dropVisible(open){ | 609 | dropVisible(open){ |
| 605 | this.broadcast('Drop', open ? 'on-update-popper' : 'on-destroy-popper'); | 610 | this.broadcast('Drop', open ? 'on-update-popper' : 'on-destroy-popper'); |
| 611 | + }, | ||
| 612 | + selectOptions(){ | ||
| 613 | + if (this.hasExpectedValue){ | ||
| 614 | + this.values = this.values.map(this.getOptionData); | ||
| 615 | + this.hasExpectedValue = false; | ||
| 616 | + } | ||
| 606 | } | 617 | } |
| 607 | } | 618 | } |
| 608 | }; | 619 | }; |