3
0
Fork 0

fix: update butterfly component for b-autocomplete, per oruga 0.11.4

actually i think these changes are from oruga 0.9.0, but i tested 0.11.4
This commit is contained in:
Lance Edgar 2025-08-02 18:56:12 -05:00
parent 905dee7e33
commit 7693b062ab

View file

@ -25,16 +25,10 @@
<%def name="make_b_autocomplete_component()">
<script type="text/x-template" id="b-autocomplete-template">
<o-autocomplete v-model="orugaValue"
:data="data"
:field="field"
:open-on-focus="openOnFocus"
:keep-first="keepFirst"
:clearable="clearable"
:clear-on-select="clearOnSelect"
:formatter="customFormatter"
:placeholder="placeholder"
@update:model-value="orugaValueUpdated"
<o-autocomplete v-model:input="orugaValue"
:options="options"
clear-icon="circle-xmark"
@update:input="orugaValueUpdated"
ref="autocomplete">
</o-autocomplete>
</script>
@ -45,12 +39,7 @@
modelValue: String,
data: Array,
field: String,
openOnFocus: Boolean,
keepFirst: Boolean,
clearable: Boolean,
clearOnSelect: Boolean,
customFormatter: null,
placeholder: String,
},
data() {
return {
@ -64,13 +53,33 @@
}
},
},
computed: {
options() {
const options = []
const field = this.field || 'label'
for (let opt of this.data) {
const newOpt = {
label: opt[field],
value: opt,
}
if (this.customFormatter) {
newOpt.label = this.customFormatter(opt)
}
options.push(newOpt)
}
return options
},
},
methods: {
focus() {
const input = this.$refs.autocomplete.$el.querySelector('input')
input.focus()
},
orugaValueUpdated(value) {
this.$emit('update:modelValue', value)
if (this.field) {
value = value[this.field]
}
this.$emit('update:modelValue', value || '')
},
},
}