Specify path for object refinement
See original GitHub issuerefine is the recommended way for validating related properties on an object https://github.com/vriad/zod/issues/61 Consider this schema
const validationSchema = z
.object({
firstName: z.string().optional(),
lastName: z.string().optional(),
email: z.string().email(),
password: z.string(),
confirmPassword: z.string(),
})
.refine((data) => data.password === data.confirmPassword, 'Both password and confirmation must match')
with this input data
{
firstName: 'zod',
lastName: '',
email: 'theba@zod.c',
password: 'thetetathea',
confirmPassword: 'thethtbet',
}
we get this error
[
{
message: 'Both password and confirmation must match',
path: [],
},
]
The path is empty. Ideally, the path should contain “confirmPassword” so that the error can be easily displayed on the UI
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
3D Object Pose Refinement — ISAAC 2020.1 documentation
A rendering of the CAD model in the scene, which requires the path to the object CAD model and file names. These correspond...
Read more >Learning to Refine Object Segments - Ronan Collobert
Abstract. Object segmentation requires both object-level information and low-level pixel data. This presents a challenge for feedforward net-.
Read more >LookML refinements | Looker - Google Cloud
This refinement can go in any LookML file in the project, such as a ... Values from the extends specified in refinements of...
Read more >towards general object understanding through recursive ...
In our model, a refinement module recursively develops understanding across space and semantics: our model gradually classifies the region into finer categories ...
Read more >RefineNet — Multi-path Refinement Network (Semantic ...
It includes 20 object categories and one background class. It is split into a training set, a validation set and a test set,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is the desired default behavior. The custom check is associated with the entire object schema. There’s no way for Zod to know that the error should be associated with
confirmPassword
in the code you provided.Though there should be a way to support your use case. My proposal: the second argument to
.refine
can also accept an object, including an optionalpath
key where you can specify the error path you’d like to be associated with the error.Something like this:
Which results in:
Would that work?
@rossholdway @etienne-dldc Tagging for interest.