Skip to content

Commit a558430

Browse files
committed
fix(PrimeInputNumber): ensure input handling only processes valid number values - fixes #80
1 parent 66a1985 commit a558430

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/components/PrimeInputNumber.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ function handleBlur(e: InputNumberBlurEvent) {
4141
}
4242
4343
function handleInput(_: any) {
44-
props.context?.node.input(_.value)
44+
if (typeof _.value === 'number' || _.value === null)
45+
props.context?.node.input(_.value)
4546
}
4647
4748
function roundToDecimals(value: any, decimals: number) {
@@ -52,13 +53,13 @@ function roundToDecimals(value: any, decimals: number) {
5253
watch(
5354
() => props.context._value,
5455
(newValue) => {
55-
if (newValue !== props.context.node.value) {
56-
if (props.context.maxFractionDigits) {
56+
// Only update if the value is different
57+
if (newValue !== props.context.node.value && typeof newValue === 'number') {
58+
if (props.context.maxFractionDigits && props.context.maxFractionDigits > 0) {
5759
// fix floating-point precision issues
5860
props.context?.node.input(roundToDecimals(newValue, props.context.maxFractionDigits))
5961
}
6062
else {
61-
// Only update if the value is different
6263
props.context?.node.input(newValue)
6364
}
6465
}

0 commit comments

Comments
 (0)