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
I want to validate the individual items inside the array and the whole array. So I want to make sure individual items is correct and the whole array is valid. There might be e.g. logic that item X cannot be in the array if it also contains item Y.
If you open the CSB and click Validate it runs the validation and you can see that validateSingleValue is called but validateArray is not called. My schema is as follows i.e. values is an array that has objects:
function validateArray(input: any): any {
console.log("validateArray called with iput", input);
return false;
}
function validateSingleValue(input: Value): any {
console.log("validateSingleValue called with iput", input);
return false;
}
const schema = z.object({
languageVersions: z.record(
z.object({
values: z
.array(
z
.object({
value1: z.string(),
value2: z.string()
})
.refine(validateSingleValue, "Value is invalid")
)
.refine(validateArray, "Array of values is invalid")
})
)
});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Codesandbox: https://codesandbox.io/s/zod-refine-array-nh5b6
Note: this seems like the same issues as #480
I want to validate the individual items inside the array and the whole array. So I want to make sure individual items is correct and the whole array is valid. There might be e.g. logic that item X cannot be in the array if it also contains item Y.
If you open the CSB and click Validate it runs the validation and you can see that
validateSingleValueis called butvalidateArrayis not called. My schema is as follows i.e. values is an array that has objects:Beta Was this translation helpful? Give feedback.
All reactions