-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Q: Partially execute a parse action #853
Comments
That's definitely achievable with If you really only care about validating certain data, but don't want the other fields to be stripped from the object, you could use |
Have you considered the approach below, that allows you to base a new schema on picking any parts of an existing schema that you want... import {z} from "zod";
const tightSchema = z.object({
id:z.string(),
rev:z.string(),
message:z.string(),
})
const {shape} = tightSchema;
const looseSchema = z.object({
message:shape.message,
id: shape.id.optional(),
}) |
Thanks for the two suggestions, I will look into it. |
This seems like this question was answered. May I close this? |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
So using vee-validate with zod for form validation brought up a thing with how zod is used in that context. So lets take a z.object({}) with some validation rules for fields. Since there is only .parse or .safeParse and so on for the whole object, this is always applied when the form validates no matter if all those values have been changed.
This brought up a problem with legacy data that might be not valid but also not changeable.
So my question is, is it possible to define a z.object({}) but then only parse certain elements of it like z.object({a, b}).parse(data, ['a']) something like that, so instead of form validation, field validation would be possible if there was a way to partially executing a schema.
One obstacle would remain though, handling refines that have a reference to a field that is not selected have to be handled too.
The text was updated successfully, but these errors were encountered: