You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Clarify structure of nested errors in a custom resolver (#1160)
* Clarify structure of nested errors in a custom resolver
The existing documentation infers that the return value of the `errors` key on a custom resolver should use flat keys that match the path of the error (since this is the convention throughout the lib), however it turns out that the internal code for RHF actually expects a hierarchy to be returned... kept me up till 3am last night tracking this one down 😅 - RHF is awesome!
* Fix incomplete path in example snippet
- A resolver can not be used with the built-in validators (e.g.: required, min, etc.)
436
436
- When building a custom resolver:
437
437
- Make sure that you return an object with both `values` and `errors` properties. Their default values should be an empty object. For example: `{}`.
438
-
- The keys of the `error` object should match the `name` values of your fields.
438
+
- The keys of the `errors` object should match the `name` values of your fields, but they _must_ be hierarchical rather than a single key for deep errors:
439
+
`❌ { "participants.1.name": someErr }` will not set or clear properly - instead, use `✅ { participants: [null, { name: someErr } ] }` as this is reachable
440
+
as `errors.participants[1].name` - you can still prepare your errors using flat keys, and then use a function like this one from the zod resolver:
0 commit comments