Skip to content

Is it possible to support Zod array and Zod object for Vue 3 validation? #906

Answered by Balastrong
KoichaDev asked this question in Q&A
Discussion options

You must be logged in to vote

As of today field validator are explicitly passed to their fields as the examples shows, however with #656 we're working on expanding the form validator to directly inject validators and errors into the fields.

In the meantime you can still use your object defining all fields and validators in one place, and pass the references in your components, like so:

Your schema defined anywhere in your code

const MyObjectSchema = z.object({
  firstName: z.string().min(3, 'First name must be at least 3 characters'),
  //... other fields
});

And then the reference in your form validators

<form.Field
  name="firstName"
  validators={{
    onChange: MyObjectSchema.shape.firstName,
...
/>

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@KoichaDev
Comment options

Answer selected by KoichaDev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants