mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-02-01 22:47:40 +00:00
fix(frontend): preserve numeric type in FormField v-model
When modelValue is a number, emit the value as a number instead of coercing to string. This prevents subtle type bugs when using FormField with numeric v-model bindings.
This commit is contained in:
@@ -11,10 +11,20 @@ interface Props {
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
defineEmits<{
|
||||
'update:modelValue': [value: string]
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: string | number]
|
||||
}>()
|
||||
|
||||
function handleInput(event: Event) {
|
||||
const value = (event.target as HTMLInputElement).value
|
||||
// Preserve numeric type if modelValue was a number
|
||||
if (typeof props.modelValue === 'number') {
|
||||
emit('update:modelValue', value === '' ? '' : Number(value))
|
||||
} else {
|
||||
emit('update:modelValue', value)
|
||||
}
|
||||
}
|
||||
|
||||
defineOptions({
|
||||
inheritAttrs: false,
|
||||
})
|
||||
@@ -83,7 +93,7 @@ defineExpose({
|
||||
v-bind="{ ...$attrs, ...inputBindings }"
|
||||
:class="inputClasses"
|
||||
:disabled="disabled || undefined"
|
||||
@input="$emit('update:modelValue', ($event.target as HTMLInputElement).value)"
|
||||
@input="handleInput"
|
||||
>
|
||||
</slot>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user