-
Version Number7.43.9 Codesandbox/Expo snackhttps://codesandbox.io/s/zealous-tristan-5cw1mz?file=/src/App.js Steps to reproduce
Expected behaviourForm should be re-validate onChange, but this doesn't occur when refine() is done on Zod's Array or Object. Revalidation seems to only happen with primitive variables. Zod throws an error for both Arrays/Objects as well as for primitive values here:
I copied the error thrown for the refinement on a primitive value, as well as the object returned for the refinement on an array in my actual application. They look very similar to me, major difference is the path, which makes me think this may be an issue with RHF and not Zod, since apparently it's throwing the error in the same way. What browsers are you seeing the problem on?Chrome Relevant log output// Error thrown for primitive variable (boolean)
{
success: false,
error: {
issues: [
{
code: "custom",
message: "Refine on boolean",
path: [
"mockedArray",
0,
"booleanProperty",
],
},
],
addIssue: (sub) => {
this.issues = [...this.issues, sub];
},
addIssues: (subs = []) => {
this.issues = [...this.issues, ...subs];
},
name: "ZodError",
},
_error: {
issues: [
{
code: "custom",
message: "Refine on boolean",
path: [
"mockedArray",
0,
"booleanProperty",
],
},
],
addIssue: (sub) => {
this.issues = [...this.issues, sub];
},
addIssues: (subs = []) => {
this.issues = [...this.issues, ...subs];
},
name: "ZodError",
},
}
// Error thrown for array
{
success: false,
error: {
issues: [
{
code: "custom",
message: "Refine on array",
path: [
"mockedArray",
],
},
],
addIssue: (sub) => {
this.issues = [...this.issues, sub];
},
addIssues: (subs = []) => {
this.issues = [...this.issues, ...subs];
},
name: "ZodError",
},
_error: {
issues: [
{
code: "custom",
message: "Refine on array",
path: [
"mockedArray",
],
},
],
addIssue: (sub) => {
this.issues = [...this.issues, sub];
},
addIssues: (subs = []) => {
this.issues = [...this.issues, ...subs];
},
name: "ZodError",
},
} Code of Conduct
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
react hook form validate field level by default, if you need to validate group of inputs then use |
Beta Was this translation helpful? Give feedback.
-
Thank you for replying! The problem I'm having with I believe this wouldn't happen if I had it like In order to do this, I have to keep track of the number of items selected every time an item's value changes. But if I use a I considered validating manually and using |
Beta Was this translation helpful? Give feedback.
-
@kiocosta You can still achieve validation on field array item at field level by using isolated component. Working demo: https://codesandbox.io/s/winter-water-y7gpw2?file=/src/App.js |
Beta Was this translation helpful? Give feedback.
@kiocosta
You can still achieve validation on field array item at field level by using isolated component.
Working demo: https://codesandbox.io/s/winter-water-y7gpw2?file=/src/App.js