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:
kolaente
2026-01-10 21:23:44 +01:00
parent 4ee29f9972
commit 182b0b63d1

View File

@@ -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>