From 179a539d4d2218be30095a153cf5d1d04839de7a Mon Sep 17 00:00:00 2001 From: ekzyis Date: Thu, 7 Mar 2024 02:45:00 +0100 Subject: [PATCH] Parse numeric strings as numbers (#902) * Parse numeric strings as numbers * Additionally check for type of field value --- components/form.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/form.js b/components/form.js index 4a275b2b..7abad582 100644 --- a/components/form.js +++ b/components/form.js @@ -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 } }) } }