Open patricknick opened 4 years ago
@jaredpalmer As formik is actively written in TypeScript and advertising the usage with yup would this something you'd change inside formik? Would you accept a MR to remove this line? Thank you.
Please stop converting empty strings to undefined as mentioned in https://github.com/formium/formik/issues/2047. This makes formik + yup unusable for me.
+1 for this. Also see https://github.com/formium/formik/issues/1697 and https://github.com/formium/formik/issues/1697#issuecomment-726772584
cc: @maddhruv @jaredpalmer
I've raised a PR fixing the same - https://github.com/formium/formik/pull/2902
I have some trouble getting my head around a breaking change introduces in Yup with version '0.29.0' in combination with Formik.
Namely it's about the following:
the types ([@types/yup](https://www.npmjs.com/package/@types/yup)) have been updated to include 'undefined' by default. TypeScript users can add '.defined()' to their schemas to account for this.
This change is rather simple and straightforward. For example, if you want to specify the following form values:
simpleInput
is required, therefore always defined.simpleInput2
is optional, but always defined with''
according to the above. But when you now submit such a form, you receive the following error from Yup:simpleInput2 must be defined
.After some research I found the following code in Formik, which changes empty string to
undefined
which then fails of course in thedefined()
validation. https://github.com/jaredpalmer/formik/blob/849ed497e24afbc1c9d41dbd0ad84db8231a48c2/packages/formik/src/Formik.tsx#L1108Full working example here: https://codesandbox.io/s/great-surf-3x642?file=/src/App.tsx
I suppose there is a good reason behind this line of code. But I'm not sure it is intended behaviour in combination with Yup. Should this be adapted on Formik side or on user-side and ideally be documented?