vael-form
API reference
Everything useForm takes and returns, and the other exports.
Options
| Name | Description |
|---|---|
schema | A Standard Schema (Zod, Valibot, ArkType, …), or a ref to one. Its input type types the fields; its output types onSubmit. |
validate | Instead of schema: a map of paths to plain functions. * is any list index, '' the form. |
defaultValues | The starting values, or a ref or getter to them. May be undefined while they load. |
onSubmit | (values, { form, event, element, submitter, formData }), called with valid values. |
onInvalid | Called when a submit fails validation, with the errors. |
showErrors | 'edited' (default), 'blur', 'input' or 'submit', or a mode per path with default. |
rules | Extra checks per path, sync or async, such as an API call. A rule can also be a schema. |
debounce | How long rules wait after the last change, in ms. |
labels | Translatable names per path, used as {field} in messages. |
i18n | An i18n instance for this form only. Usually set once on the plugin. |
id | The prefix of the inputs’ ids. Needed outside a component when you render on the server. |
Returns
| Name | Description |
|---|---|
model | A ref per field, for v-model. Groups are writable objects, lists are arrays. |
errors | The message to show per path, or nothing. A list is one entry. |
attrs | Per path, what to spread on the input: id, name, ARIA, blur, schema limits, and errorId. |
handleSubmit | The @submit handler, or handleSubmit(fn) for a handler that calls fn. |
submitting | True while onSubmit runs. |
valid | True when nothing has an error, shown or not. |
dirty | True when a value differs from its default. |
touched | True once any field has been left. |
pending | True while a rule runs. |
submitCount | How many times the form was submitted. |
values | All the values, read-only. |
errorList | The errors that are showing, as { path, message }. |
allErrors | Every error, shown or not. |
reset | reset(values?): back to the defaults, or to new ones. Nothing dirty or touched. |
validate() | validate(path?): checks the form or one group, shows its errors, and resolves to whether it’s valid. |
setValue | setValue(path, value), as a user edit. |
setValues | setValues(values), without marking anything dirty. |
setErrors | setErrors({ path: message }), such as a server’s. Each clears when its field changes. |
clearErrors | clearErrors(): clears errors set with setErrors. |
watch | watch(path, fn, { debounce, immediate }): runs on user edits and setValue, not on resets or loaded defaults. |
field | field(path): one field, with everything below. |
Field
| Name | Description |
|---|---|
value | The value, writable. |
error | The message to show, or nothing. |
touched, dirty, … | touched, dirty, valid, pending. |
attrs | What to spread on the input, with id and errorId. |
touch(), … | touch(), untouch(), validate(), reset(), watch(). |
List fields
| Name | Description |
|---|---|
items | The rows, each with a stable key, its index and its field. |
push, remove, … | push, insert, remove, move, swap, replace, clear. Touched state follows a row when it moves. |
Other exports
| Name | Description |
|---|---|
formPlugin | app.use(formPlugin, { i18n, showErrors, keyPrefix }): defaults for every form. |
provideFormConfig | The same defaults for one component tree. |
useFormContext | The form of the nearest parent that called useForm, typed with useFormContext<typeof schema>(). |
useField | useField(() => props.name): one field of the parent’s form, by name. |
msg | msg(key, params?, fallback?): a message from your own catalog, for a schema or a rule. |
validator | From vael-form/validator: a validate map as a Standard Schema. |