Partially execute a parse action #960
-
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. |
Beta Was this translation helpful? Give feedback.
Replies: 3 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 |
Beta Was this translation helpful? Give feedback.
-
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(),
}) |
Beta Was this translation helpful? Give feedback.
-
Thanks for the two suggestions, I will look into it. |
Beta Was this translation helpful? Give feedback.
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...