-
-
Notifications
You must be signed in to change notification settings - Fork 196
Open
Description
Version Number
5.1.1
Codesandbox/Expo snack
https://stackblitz.com/edit/vitejs-vite-xp4ya9ed
Steps to reproduce
- Submit the Schema / form with a complex schema.
Expected behaviour
Error message would be rendered.
https://github.com/react-hook-form/resolvers/blob/master/zod/src/zod.ts
Error message doesnt get rendered because the resolver doesnt expect unions to have a basepath. In the implementation
if (error.code === 'invalid_union') {
error.errors.forEach((unionError) =>
unionError.forEach((e) => zodErrors.push(e)
);
Union errors simply get passed down, which will result in the errors to not have a nested Path (incase where unions are more complex).
Proposed fix would be to do sth like
if (error.code === 'invalid_union') {
error.errors.forEach((unionError) =>
unionError.forEach((e) => zodErrors.push({ ...e, path: [...error.path, ...e.path] })),
);
}
What browsers are you seeing the problem on?
No response
Relevant log output
Code of Conduct
- I agree to follow this project's Code of Conduct
stefan-huckcornielheemskerk
Metadata
Metadata
Assignees
Labels
No labels