Forms guide · 4 of 8
Validation
The whole schema runs on every change, so rules across fields need nothing extra. Checks a schema shouldn’t hold, such as an API call, go in rules.
Schema libraries
Zod 4, Zod Mini, Zod 3, Valibot and ArkType map their errors to your message catalog. Yup, Joi, Effect and any other Standard Schema library work too, and show their own text. Joi needs .prefs({ abortEarly: false }) to report every problem, and Effect needs Schema.toStandardSchemaV1(schema).
// Zod
z.object({ email: z.email(), age: z.number().min(18) })
// Valibot
v.object({ email: v.pipe(v.string(), v.email()), age: v.pipe(v.number(), v.minValue(18)) })
// ArkType
type({ email: 'string.email', age: 'number >= 18' })Rules across fields schema
A rule that compares fields is a refine with a path. The error goes on the field you name and clears when either side is fixed. Valibot uses v.forward, and ArkType ctx.reject with a path.
Async checks rulesdebouncepending
rules holds checks for one path, such as an API call. Type a name: admin and vael are taken.
- A rule runs only when the schema has no error at that path, so a malformed value never reaches your API.
debouncewaits for the last change, and a newer change aborts the earlier call throughsignal.pendingis true while it runs, on the field and on the form. A submit waits for it.- It doesn’t run for the default value, so an edit form doesn’t check what the user already has.
{ on: 'blur', run }checks when the field is left instead of while typing.
Without a schema library validate
Pass validate, a map of paths to plain functions, instead of a schema. A function gets the value and { values, path }, and returns a message or nothing. An array runs in order and the first failure wins. * stands for any list index, and '' is an error no field owns. The types come from defaultValues.
The same rules on your server validator
validator() turns the same map into a Standard Schema, so it runs on a server or in a test.
import { validator } from 'vael-form/validator'
export const signup = validator<Values>({ email: [required, email], age: min(18) })
// In a component: useForm({ schema: signup, defaultValues })
// On a server: signup['~standard'].validate(body)Transforms
Transforms live in the schema. The field keeps what the user typed, and onSubmit gets what the schema returns. v-model.trim and v-model.number work as in any Vue form.
z.object({
name: z.string().trim().min(1), // " Ada " becomes "Ada"
email: z.string().trim().toLowerCase().pipe(z.email()),
price: z.string().transform(Number), // "12.5" becomes 12.5
})Limits from the schema attrs
attrs also carries what the schema says about the input: maxlength and minlength for text, min, max and step for numbers, and aria-required for a value that can’t be empty. A maxlength stops typing at the limit, so that error rarely shows. This works with Zod, Valibot and ArkType.