resolvers
resolvers copied to clipboard
[Zod] Resolver behavior changes when there are nested controllers
Describe the bug
The behavior of zodResolver handling optionals breaks in cases where there are nested path useController. Specifically, if there is some object in the form schema that is optional, the resolver will not respect that optionality if there are controllers using a nested path including one of properties of the object. The resolver should parse the same way that zod parses
To Reproduce Steps to reproduce the behavior:
- Create form schema with object as property, make it optional.
- Create input that uses a nested path with useController including one of the objects properties
- Observe that validation will fail in cases where the form state does not have the corresponding object as part of its form state.
Codesandbox link (Required)
https://codesandbox.io/s/react-hook-form-zod-resolver-example-forked-jf2ss5?file=/src/App.js
Expected behavior
The resolver should behave the same regardless of whether there is any nested useController being used with that form. If the form state is empty (as is with the example), the zodResolver should pass validation (because that's how zod works)
Additional context
I can try fix this weekend if maintainers agree it should be fixed