Fix v-model handling for grid-filter-numeric-value

This commit is contained in:
Lance Edgar 2024-04-28 02:39:40 -05:00
parent 33251e880e
commit f2f023e7b3

View file

@ -36,30 +36,15 @@
const GridFilterNumericValue = { const GridFilterNumericValue = {
template: '#grid-filter-numeric-value-template', template: '#grid-filter-numeric-value-template',
props: { props: {
value: String, ${'modelValue' if request.use_oruga else 'value'}: String,
wantsRange: Boolean, wantsRange: Boolean,
}, },
data() { data() {
const value = this.${'modelValue' if request.use_oruga else 'value'}
const {startValue, endValue} = this.parseValue(value)
return { return {
startValue: null, startValue,
endValue: null, endValue,
}
},
mounted() {
if (this.wantsRange) {
if (this.value.includes('|')) {
let values = this.value.split('|')
if (values.length == 2) {
this.startValue = values[0]
this.endValue = values[1]
} else {
this.startValue = this.value
}
} else {
this.startValue = this.value
}
} else {
this.startValue = this.value
} }
}, },
watch: { watch: {
@ -72,6 +57,12 @@
this.$emit('input', this.startValue) this.$emit('input', this.startValue)
} }
}, },
${'modelValue' if request.use_oruga else 'value'}(to, from) {
const parsed = this.parseValue(to)
this.startValue = parsed.startValue
this.endValue = parsed.endValue
},
}, },
methods: { methods: {
focus() { focus() {
@ -81,11 +72,36 @@
if (this.wantsRange) { if (this.wantsRange) {
value += '|' + this.endValue value += '|' + this.endValue
} }
this.$emit('input', value) this.$emit("${'update:modelValue' if request.use_oruga else 'input'}", value)
}, },
endValueChanged(value) { endValueChanged(value) {
value = this.startValue + '|' + value value = this.startValue + '|' + value
this.$emit('input', value) this.$emit("${'update:modelValue' if request.use_oruga else 'input'}", value)
},
parseValue(value) {
let startValue = null
let endValue = null
if (this.wantsRange) {
if (value.includes('|')) {
let values = value.split('|')
if (values.length == 2) {
startValue = values[0]
endValue = values[1]
} else {
startValue = value
}
} else {
startValue = value
}
} else {
startValue = value
}
return {
startValue,
endValue,
}
}, },
}, },
} }