Vue Forms 05 ๐ Schema Validation with Zod โ Integrating @vee-validate/zod for Fully Type-Safe Form Schemas
Vee-validate’s native validation is rule-based: each field carries its own array of rules, and the rules are written as functions or string expressions. That model is flexible, but it means the rules live in the component, the TypeScript types live somewhere else, and the shape of the validated data lives in a third place. Zod flips that around. A Zod schema is a single declaration that describes the shape, the constraints, the messages, and โ via z.infer โ the TypeScript type of its output. Everything derives from one object.
The bridge between the two libraries is toTypedSchema, exported from @vee-validate/zod. It is a small adapter that converts a Zod schema into the TypedSchema<T> interface vee-validate expects: an object with a parse method that takes unknown input and returns a value plus a list of errors keyed by path. Once a form is wired to a typed schema, useForm infers the form’s value type from the schema, defineField binds to it with autocompletion, and handleSubmit hands the submit handler a value that is already narrowed to z.infer<typeof schema>.
This chapter covers the wiring, the type inference, the error mapping, and the parts that are easy to get wrong: nested objects, arrays bound through useFieldArray, cross-field rules built with refine and superRefine, and the transforms that Zod applies but vee-validate does not write back into the form state. It ends with a ten-part example session that assembles a complete registration form from a single schema.
Key point: toTypedSchema is a one-directional adapter โ it makes the Zod schema the single source of truth for validation and for the form’s TypeScript type, but vee-validate uses the schema only to validate. The transformed output of .trim(), .transform(), and default-filled fields is not written back into the form state, so the submit handler re-parses the raw values with the same schema to obtain the clean data.
Why schema-first validation exists
The two-schema problem. Every form has two descriptions of its data: the runtime one (what is valid) and the compile-time one (what the type is). In a rule-based setup they are written twice, in two different syntaxes, by two different parts of the codebase, and they drift. A field gets a new constraint in the rule array and the TypeScript interface is not updated; the interface is updated and the rule is forgotten. A Zod schema collapses them โ z.infer<typeof schema> is derived mechanically from the same declaration that validates, so drift is impossible unless the schema itself is wrong.
The validation-library drift problem. Vee-validate’s built-in rules (required, email, min, between) are fine, but real forms need rules the built-ins do not have: “this date must be after the start date”, “this field is required unless that checkbox is set”, “this array must contain at least one item with a role of owner”. In a rule array each of those becomes a bespoke function with its own signature and its own error message convention. In Zod each is a .refine() or .superRefine() attached to the schema, composing with everything else, and โ critically โ the whole schema is testable in isolation, outside Vue, without mounting a component.
The type gap between input and output. A form field is always a string, because a DOM input cannot hold anything else. The data the form produces is not: an age is a number, a checkbox is a boolean, a date is a Date, an optional field is undefined rather than "". Zod’s coercion (z.coerce.number(), z.coerce.date()) and transforms express that gap in one place. In a rule-based setup, that conversion has to happen in the submit handler, by hand, for every field, with no guarantee that the conversion matches what the validation actually checked.
The message sprawl problem. Error copy ends up in three places in a rule-based form: the rule array, a locale file, and the template that renders errors.field. A Zod schema keeps messages where the constraint is declared, and because each issue carries a path, the adapter can route it to the correct field automatically โ no manual mapping from “this rule failed” to “this field is red”.
The trade-off. Zod is a dependency, and it is not small. It also has to be shipped to the client for client-side validation to work, which matters when the same schema is also used on a server. The benefit is a single artefact that can be reused on both sides โ the same schema validates in the browser and in the API handler, so the client and the server can never disagree about what “valid” means. A rule-based form cannot offer that, because vee-validate’s rules only exist in the browser.
a. Installing and wiring the adapter
Three packages are involved, and the split is deliberate: vee-validate is the form state and field binding, zod is the schema language, and @vee-validate/zod is the glue that implements vee-validate’s TypedSchema interface in terms of Zod’s safeParseAsync.
# vee-validate core, the schema language, and the official adapter
npm install vee-validate zod @vee-validate/zod
// src/schemas/login.ts
import { z } from "zod";
// The schema is a plain Zod object โ no Vue, no vee-validate, no component
export const loginSchema = z.object({
email: z.string().min(1, "Email is required").email("Enter a valid email"), // two rules, two messages
password: z.string().min(8, "At least 8 characters"), // length rule with custom copy
});
// The type is derived, never hand-written
export type LoginValues = z.infer<typeof loginSchema>;
// => { email: string; password: string }
The schema file has no knowledge of the UI. That is the point: it can be imported by a Vue component, by a Node API route, and by a unit test, and all three get the identical rules and the identical type.
The adapter itself is a function call. toTypedSchema accepts any ZodType and returns a TypedSchema<T> where T is inferred from the schema’s output.
// src/components/LoginForm.vue
<script setup lang="ts">
import { useForm } from "vee-validate";
import { toTypedSchema } from "@vee-validate/zod";
import { loginSchema } from "@/schemas/login";
// toTypedSchema wraps the Zod schema in vee-validate's expected shape
const { errors, handleSubmit, defineField, meta } = useForm({
validationSchema: toTypedSchema(loginSchema), // T is inferred as LoginValues
});
</script>
useForm receives a validationSchema option. If the schema is passed directly โ rather than assigned to a variable that vee-validate cannot inspect โ the generic T is inferred from TypedSchema<T>, which is itself derived from the Zod schema. No <LoginValues> type argument is needed, and adding one manually is a common way to introduce a mismatch.
If the schema depends on reactive state (a locale, a mode, a fetched configuration), pass a function instead of a value. Vee-validate calls it on every validation run.
// A schema that changes with the app state: it is re-evaluated on each validation
const { errors } = useForm({
validationSchema: () => toTypedSchema(registrationSchemaFor(state.accountType)),
});
b. The schema as the source of truth for binding and submission
Once the form is typed, every downstream call inherits the type. This is the payoff of the adapter, and it shows up in three places: defineField, errors, and the handleSubmit callback.
defineField takes a key of the form’s value type. Type the key wrong and TypeScript fails at compile time; the errors object is keyed the same way.
<script setup lang="ts">
const { errors, handleSubmit, defineField, meta } = useForm({
validationSchema: toTypedSchema(loginSchema),
});
// Both bindings are checked against LoginValues at compile time
const [email, emailAttrs] = defineField("email");
const [password, passwordAttrs] = defineField("password");
// const [typo, ...] = defineField("emial"); // โ compile error, caught by the schema type
</script>
<template>
<form @submit="handleSubmit">
<!-- v-model binds the value; v-bind spreads onBlur and the aria attributes -->
<input v-model="email" v-bind="emailAttrs" type="email" />
<span v-if="errors.email">{{ errors.email }}</span>
<input v-model="password" v-bind="passwordAttrs" type="password" />
<span v-if="errors.password">{{ errors.password }}</span>
<button type="submit" :disabled="!meta.valid">Sign in</button>
</form>
</template>
The emailAttrs object returned by defineField carries the blur handler that triggers validation for that field. Without v-bind, the field validates only on submit โ which is why so many zod integrations appear to validate “too late”.
handleSubmit is where the type narrowing completes. The callback receives the validated values, typed as z.infer<typeof schema>.
const onSubmit = handleSubmit((values) => {
// `values` is LoginValues, not `unknown` or `Record<string, any>`
console.log(values.email.toUpperCase()); // safe: email is a string
console.log(values.password.length); // safe: password is a string
});
There is a subtlety worth stating plainly. Vee-validate calls the schema to validate, and the schema returns a parsed value โ but vee-validate keeps the form state as the user typed it. A Zod transform like .trim() or .toLowerCase() affects what the schema returns, not what values contains inside handleSubmit. The reliable pattern is to re-parse in the handler with the same schema.
const onSubmit = handleSubmit((values) => {
// Re-parse to obtain the schema's OUTPUT, including transforms and defaults
const data = loginSchema.parse(values);
// `data.email` is trimmed and lowercased if the schema says so;
// `values.email` is still exactly what the user typed
send(data);
});
This pattern also makes the input and output types explicit. When a schema uses transforms, z.input<typeof schema> is the shape the form holds and z.output<typeof schema> is the shape the API receives. They differ, and useForm is typed against the input side.
// input: what the form fields hold โ all strings
type RegisterInput = z.input<typeof registerSchema>;
// output: what the API receives โ numbers, trimmed strings, defaults applied
type RegisterOutput = z.output<typeof registerSchema>;
c. Error paths, nested objects, arrays, and cross-field rules
The adapter’s job during a failed parse is to turn Zod’s issue list into vee-validate’s error map. Every Zod issue carries a path array โ ["email"], ["address", "city"], ["contacts", 0, "email"] โ and the adapter joins that path into a dotted string, which vee-validate normalises to the same field name that defineField and useFieldArray use. This is why nested and array fields light up correctly without any manual mapping.
Nested objects are addressed with dotted names. The schema declares the object; the component binds the leaf.
// The schema declares the nesting once
const shippingSchema = z.object({
recipient: z.string().min(1, "Required"),
address: z.object({
city: z.string().min(1, "City is required"),
postalCode: z.string().regex(/^\d{5}$/, "Five digits"),
}),
});
// The component binds the leaf path โ the same dotted path Zod reports
const [city, cityAttrs] = defineField("address.city");
const [postalCode, postalAttrs] = defineField("address.postalCode");
Arrays are the case where the adapter and useFieldArray must agree. useFieldArray manages the list of row keys; each row’s individual fields are still bound with an indexed path.
import { useFieldArray } from "vee-validate";
const contactSchema = z.object({
contacts: z
.array(z.object({ email: z.string().email("Invalid"), name: z.string().min(1, "Required") }))
.min(1, "Add at least one contact"),
});
const { fields, push, remove } = useFieldArray<{ email: string; name: string }>("contacts");
// Render each row with defineField(`contacts[${index}].email`)
The .min(1) on the array produces an issue whose path is just ["contacts"], so the error lands on the list itself rather than on any row. Rendering errors.contacts next to the “Add contact” button is the natural place for it.
Cross-field rules use refine or superRefine. The important detail is the path option: without it the issue has an empty path and becomes a form-level error, which is harder to render. Giving the issue a path attaches it to the field the user must fix.
const passwordSchema = z
.object({
password: z.string().min(8, "At least 8 characters"),
confirmPassword: z.string(),
})
// The rule spans both fields, but the error is attached to the second one
.refine((v) => v.password === v.confirmPassword, {
message: "Passwords do not match",
path: ["confirmPassword"], // without this, the error has no field to render on
});
superRefine is the imperative form, useful when a single check yields several issues with different paths.
const bookingSchema = z
.object({ start: z.coerce.date(), end: z.coerce.date() })
.superRefine((v, ctx) => {
if (v.end <= v.start) {
// Attach the problem to the field that must change
ctx.addIssue({ code: "custom", message: "Must be after the start", path: ["end"] });
}
});
A root-level issue with no path is still surfaced โ vee-validate stores it under the empty-string key in the errors map โ but rendering it requires knowing that convention. Attaching a path is simpler and more precise, and it keeps the error next to the input it belongs to.
Complete Example Session
// ============================================
// PART 1: THE SCHEMA โ SINGLE SOURCE OF TRUTH
// ============================================
// src/schemas/register.ts
import { z } from "zod";
export const registerSchema = z
.object({
// Coerced from the DOM string to a number, with a range check
age: z.coerce.number({ invalid_type_error: "Enter a number" }).min(18, "Must be 18 or older"),
// Trimmed in the output, validated as a string in the input
name: z.string().trim().min(2, "At least 2 characters"),
email: z.string().min(1, "Required").email("Enter a valid email"),
password: z.string().min(8, "At least 8 characters"),
confirmPassword: z.string(),
// Nested object โ paths become "address.city" etc.
address: z.object({
city: z.string().min(1, "City is required"),
postalCode: z.string().regex(/^\d{5}$/, "Five digits"),
}),
// Array โ a row-level path and a list-level min() rule
contacts: z
.array(z.object({ name: z.string().min(1, "Required"), email: z.string().email("Invalid") }))
.min(1, "Add at least one contact"),
})
// Cross-field rule pinned to a specific field path
.refine((v) => v.password === v.confirmPassword, {
message: "Passwords do not match",
path: ["confirmPassword"],
});
// ============================================
// PART 2: THE TYPES โ DERIVED, NEVER WRITTEN
// ============================================
// The form holds the INPUT side (strings from the DOM, before coercion)
export type RegisterInput = z.input<typeof registerSchema>;
// The API receives the OUTPUT side (numbers coerced, strings trimmed)
export type RegisterOutput = z.output<typeof registerSchema>;
// ============================================
// PART 3: THE FORM โ TYPE INFERENCE FROM THE SCHEMA
// ============================================
// src/components/RegisterForm.vue
<script setup lang="ts">
import { useForm, useFieldArray } from "vee-validate";
import { toTypedSchema } from "@vee-validate/zod";
import { registerSchema } from "@/schemas/register";
const { errors, handleSubmit, defineField, meta, resetForm } = useForm({
// T is inferred as RegisterInput from the TypedSchema wrapper
validationSchema: toTypedSchema(registerSchema),
// Seed the form with the schema's shape so every field starts controlled
initialValues: { contacts: [{ name: "", email: "" }], address: { city: "", postalCode: "" } },
});
// ============================================
// PART 4: THE FLAT FIELDS โ BINDING WITH defineField
// ============================================
const [name, nameAttrs] = defineField("name");
const [email, emailAttrs] = defineField("email");
const [age, ageAttrs] = defineField("age");
const [password, passwordAttrs] = defineField("password");
const [confirmPassword, confirmAttrs] = defineField("confirmPassword");
// ============================================
// PART 5: THE NESTED FIELDS โ DOTTED PATHS
// ============================================
const [city, cityAttrs] = defineField("address.city");
const [postalCode, postalAttrs] = defineField("address.postalCode");
// ============================================
// PART 6: THE ARRAY FIELDS โ useFieldArray
// ============================================
// One array field manages the row identity; each row binds indexed paths
const { fields, push, remove } = useFieldArray<{ name: string; email: string }>("contacts");
// ============================================
// PART 7: THE SUBMIT HANDLER โ RE-PARSE FOR OUTPUT
// ============================================
const onSubmit = handleSubmit((values) => {
// `values` is RegisterInput โ the raw DOM-shaped data
// Re-parse with the same schema to get the trimmed/coerced RegisterOutput
const data: RegisterOutput = registerSchema.parse(values);
// `data.age` is a number, `data.name` is trimmed โ `values.age` would still be a string
createAccount(data);
});
// ============================================
// PART 8: THE RESET โ BACK TO A KNOWN STATE
// ============================================
function clear() {
// Reset restores initialValues and clears the error map in one call
resetForm();
}
</script>
<!-- ============================================ -->
<!-- PART 9: THE TEMPLATE โ ERRORS RENDERED BY PATH -->
<!-- ============================================ -->
<template>
<form @submit="onSubmit">
<input v-model="name" v-bind="nameAttrs" />
<span v-if="errors.name">{{ errors.name }}</span>
<input v-model="email" v-bind="emailAttrs" type="email" />
<span v-if="errors.email">{{ errors.email }}</span>
<input v-model="age" v-bind="ageAttrs" type="number" />
<span v-if="errors.age">{{ errors.age }}</span>
<!-- Nested paths render exactly like flat ones -->
<input v-model="city" v-bind="cityAttrs" />
<span v-if="errors['address.city']">{{ errors["address.city"] }}</span>
<!-- The array's own min(1) rule lands on the list, not on a row -->
<p v-if="errors.contacts">{{ errors.contacts }}</p>
<div v-for="(field, index) in fields" :key="field.key">
<input v-model="field.value.name" :name="`contacts[${index}].name`" />
<span v-if="errors[`contacts[${index}].name`]">{{ errors[`contacts[${index}].name`] }}</span>
<button type="button" @click="remove(index)">Remove</button>
</div>
<button type="button" @click="push({ name: '', email: '' })">Add contact</button>
<button type="submit" :disabled="!meta.valid">Register</button>
</form>
</template>
// ============================================
// PART 10: THE PRIMITIVE FIELD โ useField WITH A SCHEMA
// ============================================
// A single field, validated by a single Zod schema, outside any form
import { useField } from "vee-validate";
const { value: coupon, errorMessage } = useField(
"coupon",
toTypedSchema(z.string().regex(/^[A-Z0-9]{8}$/, "Eight uppercase characters")),
);
The ten parts covered the schema, the derived input and output types, the useForm wiring, the flat and nested field bindings, the useFieldArray list, the re-parsing submit handler, the reset, the template that renders errors by their dotted path, and the standalone useField case.
Quick Reference
The Adapter Surface
| Export | Package | Purpose |
|---|---|---|
toTypedSchema(zodSchema) | @vee-validate/zod | Wrap a Zod schema as TypedSchema<T> |
useForm({ validationSchema }) | vee-validate | Form state, infers T from the schema |
useField(name, schema) | vee-validate | Single field, accepts a TypedSchema |
TypedSchema<T> | vee-validate | The { parse } interface the adapter implements |
Zod Pattern to Form Behaviour
| Zod pattern | Form behaviour |
|---|---|
z.string().min(1) | Required-string rule on one field |
z.string().email() | Email format, one message |
z.coerce.number() | DOM string coerced to number in the output |
z.string().trim() | Output trimmed; form state keeps the raw string |
z.object({...}) | Nested fields at parent.child paths |
z.array(...) | Bind via useFieldArray, indexed paths |
.refine(fn, { path }) | Cross-field rule attached to one field |
.superRefine((v, ctx) => ...) | Multiple issues, each with its own path |
Type Helpers
| Helper | Meaning |
|---|---|
z.infer<typeof s> | Output type (z.output is the alias) |
z.input<typeof s> | Input type โ what the form holds |
z.output<typeof s> | Output type โ what the API receives |
Path Mapping
| Zod issue path | vee-validate error key |
|---|---|
["email"] | errors.email |
["address", "city"] | errors["address.city"] |
["contacts", 0, "email"] | errors["contacts[0].email"] |
["contacts"] | errors.contacts (the list itself) |
[] | Form-level error, empty-string key |
Best Practices
โ Do This:
// Derive the type from the schema
type Values = z.infer<typeof schema>; // โ
// Re-parse in the handler to get the transformed output
const data = schema.parse(values); // โ
// Attach cross-field errors to a field path
.refine(fn, { path: ["confirmPassword"] }) // โ
// Bind the attrs so blur triggers validation
<input v-model="email" v-bind="emailAttrs" /> // โ
// Give array rules a message on the list
z.array(item).min(1, "Add at least one") // โ
// Keep the schema in its own module, free of Vue
export const registerSchema = z.object({ ... }); // โ
// Use a function when the schema is reactive
validationSchema: () => toTypedSchema(schemaFor(mode)) // โ
โ Don’t Do This:
// Hand-write the interface next to the schema
interface Values { email: string } // โ
// Expect transforms to appear in the form state
values.email.trim(); // not applied by validation // โ
// Leave a refine without a path
.refine(fn, { message: "Invalid" }) // โ
// Skip v-bind and validate only on submit
<input v-model="email" /> // โ
// Hand-type the useForm generic
useForm<SomeGuess>({ validationSchema: ... }) // โ
// Define the schema inline in the component
useForm({ validationSchema: toTypedSchema(z.object({...})) }) // โ
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| Fields never turn red while typing | v-bind="attrs" omitted | Bind the returned attrs |
| Values look untrimmed on submit | Validation does not write back | schema.parse(values) in the handler |
| Error shows nowhere | refine had no path | Add path: ["field"] |
| Array errors target the wrong row | Row paths not indexed | Use contacts[${i}].email |
Type mismatch on handleSubmit | Manual generic on useForm | Let inference run |
.email() on a required field | Empty string fails email() | Chain .min(1) first |
| Number arrives as a string | No coercion in the schema | z.coerce.number() |
| Schema re-created every render | Inline z.object() in setup | Hoist to a module |
Real-World Examples
1. Login schema
const login = z.object({ email: z.string().email(), password: z.string().min(8) });
2. Wiring the form
const { handleSubmit } = useForm({ validationSchema: toTypedSchema(login) });
3. Derived type
type Login = z.infer<typeof login>; // { email: string; password: string }
4. Coerced number
age: z.coerce.number().min(18);
5. Password confirmation
.refine((v) => v.a === v.b, { path: ["b"], message: "No match" });
6. Nested address
const [city] = defineField("address.city");
7. Array binding
const { fields, push } = useFieldArray("contacts");
8. Array minimum
contacts: z.array(item).min(1, "Add at least one");
9. Re-parse on submit
const data = schema.parse(values);
10. Standalone field
useField("coupon", toTypedSchema(z.string().regex(/^[A-Z0-9]{8}$/)));
Visual
The Adapter Pipeline
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ZOD SCHEMA โ
โ z.object({ email, password }) โ
โ โ โ
โ โผ โ
โ toTypedSchema(schema) โโโ @vee-validate/zod โ
โ โ โ
โ โผ โ
โ TypedSchema<T> { parse(values) -> { value, errors } } โ
โ โ โ
โ โผ โ
โ useForm({ validationSchema }) โ
โ โ โ
โ โผ โ
โ { errors, values, meta, handleSubmit, defineField } โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
From Issue Path to Error Key
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ZOD ISSUE โ
โ { path: ["contacts", 0, "email"], message: "Invalid" } โ
โ โ โ
โ โผ adapter joins the path โ
โ "contacts.0.email" โ
โ โ โ
โ โผ vee-validate normalises the index โ
โ "contacts[0].email" โ
โ โ โ
โ โผ โ
โ errors["contacts[0].email"] === "Invalid" โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The Transform Gap
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ USER TYPES " Bob " โ
โ โ โ
โ โโโโโโโโโโโโบ form state: " Bob " โ
โ โ โ โ
โ โ โผ handleSubmit(values) โ
โ โ values.name = " Bob " โ
โ โ โ
โ โโโโโโโโโโโโบ schema.parse() -> output โ
โ { name: "Bob" } โ
โ โ
โ The form state is never rewritten by validation. โ
โ Re-parse to get the trimmed value. โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Where the Rules Live
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ schemas/register.ts (no Vue, no DOM) โ
โ z.object({ ... }) โ
โ .refine(...) โ
โ โ โ
โ โโโโบ RegisterForm.vue client validation โ
โ โโโโบ api/register.ts server validation โ
โ โโโโบ register.test.ts unit tests โ
โ โ
โ One declaration, three consumers, zero drift. โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Summary
| Item | Value |
|---|---|
| Adapter | toTypedSchema from @vee-validate/zod |
| Form option | validationSchema: toTypedSchema(schema) |
| Type source | z.infer<typeof schema> |
| Input type | z.input<typeof schema> โ the form state |
| Output type | z.output<typeof schema> โ the API payload |
| Error routing | Zod issue path โ dotted error key |
| Nested fields | Dotted binding: defineField("address.city") |
| Array fields | useFieldArray plus indexed paths |
| Cross-field | .refine(fn, { path: [...] }) |
| Transforms | Not written back โ re-parse on submit |
Key takeaways:
toTypedSchemais the only bridge. It converts a Zod schema into vee-validate’sTypedSchema<T>interface, which is aparsemethod returning a value and a path-keyed error list. Nothing else changes about how the form works.- The schema replaces the type declaration.
z.infer<typeof schema>is derived mechanically, so the compile-time shape and the runtime rules cannot drift apart. Hand-writing an interface alongside the schema re-creates the problem the adapter exists to remove. - Errors route themselves. Every Zod issue carries a
patharray; the adapter joins it and vee-validate normalises it into the same dotted key thatdefineFieldanduseFieldArrayuse. Nested objects and array rows light up without any manual mapping. - Cross-field rules need an explicit path. A
refinewithoutpathproduces a root-level issue that has no field to render on. Naming the field inpathkeeps the message next to the input that must change. - Validation does not rewrite form state. Transforms, trimming, coercion, and defaults affect the schema’s output, not the values vee-validate holds. Re-parse in the submit handler with the same schema to get the clean payload.
- One schema serves both sides. Because the schema file has no Vue dependency, the same declaration validates in the component, in the API route, and in a unit test โ the client and the server can never disagree about what valid means.
Remember: The adapter is a one-way street. toTypedSchema gives the form a schema to validate against and a type to infer from, but it does not make vee-validate adopt Zod’s understanding of the data. The form state stays in the shape the DOM produced; the schema’s coerced, trimmed, transformed output has to be requested again at submit time. Keep the schema in its own module, derive every type from it, give every cross-field rule a path, and the form, the API, and the tests all read from one declaration.
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!