Skip to content

Commit

Permalink
Parse numeric strings as numbers (#902)
Browse files Browse the repository at this point in the history
* Parse numeric strings as numbers

* Additionally check for type of field value
  • Loading branch information
ekzyis authored Mar 7, 2024
1 parent b38a5e6 commit 179a539
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion components/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,9 @@ function InputInner ({
if (draft) {
// for some reason we have to turn off validation to get formik to
// not assume this is invalid
helpers.setValue(draft, false)
const isNumeric = /^[0-9]+$/.test(draft)
const numericExpected = typeof field.value === 'number'
helpers.setValue(isNumeric && numericExpected ? parseInt(draft) : draft, false)
onChange && onChange(formik, { target: { value: draft } })
}
}
Expand Down

0 comments on commit 179a539

Please sign in to comment.