diff --git a/src/utils/events.ts b/src/utils/events.ts index 5fa06fb5d..8ef0050dd 100644 --- a/src/utils/events.ts +++ b/src/utils/events.ts @@ -1,4 +1,4 @@ -import { isCallable, toArray } from './index'; +import { isCallable, toArray, isNaN } from './index'; export const isEvent = (evt: any): evt is Event => { if (!evt) { @@ -18,15 +18,30 @@ export const isEvent = (evt: any): evt is Event => { return false; }; +type BoundInputElement = HTMLInputElement & { + _vModifiers?: { number?: boolean; trim?: boolean }; +}; + export function normalizeEventValue(value: unknown): any { if (!isEvent(value)) { return value; } - const input = value.target as HTMLInputElement; + const input = value.target as BoundInputElement; if (input.type === 'file' && input.files) { return toArray(input.files); } + // If the input has a `v-model.number` modifier applied. + if (input._vModifiers && input._vModifiers.number) { + // as per the spec the v-model.number uses parseFloat + const valueAsNumber = parseFloat(input.value); + if (isNaN(valueAsNumber)) { + return input.value; + } + + return valueAsNumber; + } + return input.value; }