Forms guide · 1 of 8
Your first form
A form is one call to useForm. It returns refs for the values, the errors to show, and the attributes each input needs.
Install
vael-form is its own package. Add it with a schema library. Zod is used on these pages; Valibot, ArkType and any other Standard Schema library work the same way.
pnpm add vael-form zodA form useFormmodelerrorsattrshandleSubmit
Give useForm a schema, the starting values and what to do with valid values. Then bind each input by its name. Leave a field empty and tab on: nothing shows. Type something wrong, then leave it, and the error appears.
modelholds a ref per field. Destructure it, then usev-model="email"as on any ref.attrs.emailgoes on the input:id,name,aria-invalid,aria-describedby, and the blur that marks the field as left.errors.emailis the message to show, or nothing.handleSubmitgoes on@submit. It validates, focuses the first invalid field, and callsonSubmitwith the schema’s output.
Form state validdirtytouchedsubmittingvalues
The form’s state is refs you can destructure and use in a template without .value. Edit the name and watch them change. reset() goes back to the defaults, or makes new ones: here, a save makes the saved values the new defaults.
Radios, checkboxes and numbers
Every control binds the same way. A group of radios or checkboxes is one field with one error, so its attrs go on the group, and the field counts as left when focus leaves the whole group. A list field bound to several checkboxes holds the checked values, as in plain Vue.
With vael-ui and other libraries attrs
Spread attrs on a component as on an input. Inside vael-ui’s Field, the Field keeps its own id, so its label still names the control, and it merges your aria-describedby with its error. With a library that lets a passed id replace its own, pass only what it needs: :name="attrs.email.name" and @focusout="attrs.email.onFocusout".
<Field label="Email" :error="errors.email">
<Input v-model="email" v-bind="attrs.email" />
</Field>