Tweak the buefy autocomplete component a bit
to better support staying in sync w/ data on the caller/parent side
This commit is contained in:
parent
493785591c
commit
c32f47ba95
|
@ -22,23 +22,42 @@ const TailboneAutocomplete = {
|
||||||
data: [],
|
data: [],
|
||||||
selected: selected,
|
selected: selected,
|
||||||
isFetching: false,
|
isFetching: false,
|
||||||
autocompleteValue: this.value,
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
value(to, from) {
|
||||||
|
if (from && !to) {
|
||||||
|
this.clearSelection(false)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
clearSelection() {
|
clearSelection(focus) {
|
||||||
|
if (focus === undefined) {
|
||||||
|
focus = true
|
||||||
|
}
|
||||||
this.selected = null
|
this.selected = null
|
||||||
this.autocompleteValue = null
|
this.value = null
|
||||||
|
if (focus) {
|
||||||
this.$nextTick(function() {
|
this.$nextTick(function() {
|
||||||
this.$refs.autocomplete.focus()
|
this.$refs.autocomplete.focus()
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: should emit event for caller logic (can they cancel?)
|
// TODO: should emit event for caller logic (can they cancel?)
|
||||||
// $('#' + oid + '-textbox').trigger('autocompletevaluecleared');
|
// $('#' + oid + '-textbox').trigger('autocompletevaluecleared');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getDisplayText() {
|
||||||
|
if (this.selected) {
|
||||||
|
return this.selected.label
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
},
|
||||||
|
|
||||||
// TODO: should we allow custom callback? or is event enough?
|
// TODO: should we allow custom callback? or is event enough?
|
||||||
// function (oid) {
|
// function (oid) {
|
||||||
// $('#' + oid + '-textbox').on('autocompletevaluecleared', function() {
|
// $('#' + oid + '-textbox').on('autocompletevaluecleared', function() {
|
||||||
|
@ -62,7 +81,9 @@ const TailboneAutocomplete = {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
itemSelected(value) {
|
itemSelected(value) {
|
||||||
|
if (this.selected || !value) {
|
||||||
this.$emit('input', value)
|
this.$emit('input', value)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: buefy example uses `debounce()` here and perhaps we should too?
|
// TODO: buefy example uses `debounce()` here and perhaps we should too?
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
<b-autocomplete ref="autocomplete"
|
<b-autocomplete ref="autocomplete"
|
||||||
:name="name"
|
:name="name"
|
||||||
v-show="!selected"
|
v-show="!selected"
|
||||||
v-model="autocompleteValue"
|
v-model="value"
|
||||||
:data="data"
|
:data="data"
|
||||||
@typing="getAsyncData"
|
@typing="getAsyncData"
|
||||||
@select="selectionMade"
|
@select="selectionMade"
|
||||||
|
|
Loading…
Reference in a new issue