Open shobhanbiswas11 opened 2 years ago
I ran into this issue — it actually does work; however the refine
& superRefine
methods don't get called if there are validation errors coming from inside that object
— so only if there are no other errors will the errors from refine/superRefine actually surface.
This is an issue with how Zod works, rather than this library.
Edit: Actually you're right; the errors don't surface at all with this package. I copy-pasted the main index.ts
into my codebase and got it working like I detailed above. Super weird
@iest can you add which versions of Zod and Formik you were using when testing?
@robertLichtnow not 100% sure as it's been a few months, but my yarn.lock says formik: ^2.2.9
and zod: ^3.19.1
I observed the same behaviour and noticed the following… In my case, I have custom input control driven by Formik's useField()
hook. It's a custom combobox with ability to specify custom value. Here are my observations where .refine
is defined for all conditions:
helpers.setError()
, .refine()
is ignoredhelpers.setValue()
, .refine
overrides with its own validation.refine()
overrides with its own validation.refine()
is ignoredEdit: added 4th bullet point
Another observation I noticed today. If you define .refine()
on schema itself, not individual field, it is also ignored.
Is there a workaround people are using for this? I'd specifically like to do password confirmation
try assign validate to formik validate={toFormikValidate(Schema)} and its work
Describe the bug Does not parse properly if the error is coming from refine or superRefine
To Reproduce
if the values are these
It does not add any error for confirmPassword field with message "Passwords don't match"
Node version: v16.15.0
Zod, Formik and zod-formik-adapter versions: