formik icon indicating copy to clipboard operation
formik copied to clipboard

empty string is transformed to undefined. Why do you want to do that?

Open bchenSyd opened this issue 3 years ago • 5 comments

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?

bchenSyd avatar Mar 12 '21 00:03 bchenSyd

why do you explicitly convert an empty string into undefined?

bchenSyd avatar Mar 12 '21 00:03 bchenSyd

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

github-actions[bot] avatar Apr 12 '21 00:04 github-actions[bot]

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

github-actions[bot] avatar Jul 13 '21 00:07 github-actions[bot]

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

github-actions[bot] avatar Aug 13 '21 00:08 github-actions[bot]

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?

ParallelUniv3rse avatar May 07 '24 09:05 ParallelUniv3rse