mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-04-25 06:35:32 +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>()
|
const props = defineProps<Props>()
|
||||||
defineEmits<{
|
const emit = defineEmits<{
|
||||||
'update:modelValue': [value: string]
|
'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({
|
defineOptions({
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
})
|
})
|
||||||
@@ -83,7 +93,7 @@ defineExpose({
|
|||||||
v-bind="{ ...$attrs, ...inputBindings }"
|
v-bind="{ ...$attrs, ...inputBindings }"
|
||||||
:class="inputClasses"
|
:class="inputClasses"
|
||||||
:disabled="disabled || undefined"
|
:disabled="disabled || undefined"
|
||||||
@input="$emit('update:modelValue', ($event.target as HTMLInputElement).value)"
|
@input="handleInput"
|
||||||
>
|
>
|
||||||
</slot>
|
</slot>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user