formik
formik copied to clipboard
empty string is transformed to undefined. Why do you want to do that?
i have a field set to an empty string in invitalValues
, but in my validation
, I noticed formik
passed me undefined
instead.
I thought it is a but but after digging into source code, I found that this is an intended behaviour in prepareDataForValidation
https://github.com/formium/formik/blob/34a11422bf1619236bc9fdb1b7c4f0d285638702/packages/formik/src/Formik.tsx#L1101
so what's the idea behind this?
why do you explicitly convert an empty string into undefined
?
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days
This is not stale, it's still a problem. Original issue #805 was not resolved. When submitting a form:
- my validation receives
undefined
instead of empty string and passes (I allow missing value but disallow an empty string) - the onSubmit callback receives
""
and I submit empty string to the server even though I've specifically written validation agains it.
Frustrating. As it seems from #805, it is part of some legacy code that is no longer needed, though it will cause a breaking change. Would it be alright to draft a PR where this behavior is removed?