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