Skip to content

Commit 179a539

Browse files
authored
Parse numeric strings as numbers (#902)
* Parse numeric strings as numbers * Additionally check for type of field value
1 parent b38a5e6 commit 179a539

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

components/form.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,9 @@ function InputInner ({
450450
if (draft) {
451451
// for some reason we have to turn off validation to get formik to
452452
// not assume this is invalid
453-
helpers.setValue(draft, false)
453+
const isNumeric = /^[0-9]+$/.test(draft)
454+
const numericExpected = typeof field.value === 'number'
455+
helpers.setValue(isNumeric && numericExpected ? parseInt(draft) : draft, false)
454456
onChange && onChange(formik, { target: { value: draft } })
455457
}
456458
}

0 commit comments

Comments
 (0)