Skip to content

Commit 5456777

Browse files
author
Pavlo Kulyk
committed
fix: improve number input handling with NaN check and emit null value
1 parent 87a6483 commit 5456777

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

adminforth/spa/src/afcl/Input.vue

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,26 @@ const emit = defineEmits<{
6060
6161
const onInput = (e: Event) => {
6262
const el = e.target as HTMLInputElement;
63-
let val = Number(el.value);
63+
const raw = el.value;
6464
65-
if (props.min !== null && props.min !== undefined && val < props.min) val = props.min;
66-
if (props.max !== null && props.max !== undefined && val > props.max) val = props.max;
65+
if (props.type === 'number') {
66+
const num = Number(raw);
6767
68-
el.value = String(val);
69-
emit('update:modelValue', val);
68+
if (isNaN(num)) {
69+
emit('update:modelValue', null);
70+
return;
71+
}
72+
73+
let val = num;
74+
75+
if (props.min != null && val < props.min) val = props.min;
76+
if (props.max != null && val > props.max) val = props.max;
77+
78+
el.value = String(val);
79+
emit('update:modelValue', val);
80+
} else {
81+
emit('update:modelValue', raw);
82+
}
7083
};
7184
7285

0 commit comments

Comments
 (0)