Skip to content

Commit fc41691

Browse files
committed
fix: handle NaN when parsing number inputs closes #4328
1 parent 435e785 commit fc41691

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

.changeset/neat-phones-crash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'vee-validate': patch
3+
---
4+
5+
fix: handle NaN when parsing number inputs closes #4328

packages/vee-validate/src/utils/events.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getBoundValue, hasValueBinding } from './vnode';
33

44
function parseInputValue(el: HTMLInputElement) {
55
if (el.type === 'number') {
6-
return el.valueAsNumber;
6+
return Number.isNaN(el.valueAsNumber) ? el.value : el.valueAsNumber;
77
}
88

99
return el.value;

packages/vee-validate/tests/useField.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,10 @@ describe('useField()', () => {
892892
setValue(input, '123');
893893
await flushPromises();
894894
expect(field.value.value).toBe(123);
895+
896+
setValue(input, '');
897+
await flushPromises();
898+
expect(field.value.value).toBe('');
895899
});
896900

897901
test('a validator can return multiple messages', async () => {

0 commit comments

Comments
 (0)