vael-ui v0.5.7

vael-form

API reference

Everything useForm takes and returns, and the other exports.

Options

NameDescription
schemaA Standard Schema (Zod, Valibot, ArkType, …), or a ref to one. Its input type types the fields; its output types onSubmit.
validateInstead of schema: a map of paths to plain functions. * is any list index, '' the form.
defaultValuesThe 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.
onInvalidCalled when a submit fails validation, with the errors.
showErrors'edited' (default), 'blur', 'input' or 'submit', or a mode per path with default.
rulesExtra checks per path, sync or async, such as an API call. A rule can also be a schema.
debounceHow long rules wait after the last change, in ms.
labelsTranslatable names per path, used as {field} in messages.
i18nAn i18n instance for this form only. Usually set once on the plugin.
idThe prefix of the inputs’ ids. Needed outside a component when you render on the server.

Returns

NameDescription
modelA ref per field, for v-model. Groups are writable objects, lists are arrays.
errorsThe message to show per path, or nothing. A list is one entry.
attrsPer path, what to spread on the input: id, name, ARIA, blur, schema limits, and errorId.
handleSubmitThe @submit handler, or handleSubmit(fn) for a handler that calls fn.
submittingTrue while onSubmit runs.
validTrue when nothing has an error, shown or not.
dirtyTrue when a value differs from its default.
touchedTrue once any field has been left.
pendingTrue while a rule runs.
submitCountHow many times the form was submitted.
valuesAll the values, read-only.
errorListThe errors that are showing, as { path, message }.
allErrorsEvery error, shown or not.
resetreset(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.
setValuesetValue(path, value), as a user edit.
setValuessetValues(values), without marking anything dirty.
setErrorssetErrors({ path: message }), such as a server’s. Each clears when its field changes.
clearErrorsclearErrors(): clears errors set with setErrors.
watchwatch(path, fn, { debounce, immediate }): runs on user edits and setValue, not on resets or loaded defaults.
fieldfield(path): one field, with everything below.

Field

NameDescription
valueThe value, writable.
errorThe message to show, or nothing.
touched, dirty, …touched, dirty, valid, pending.
attrsWhat to spread on the input, with id and errorId.
touch(), …touch(), untouch(), validate(), reset(), watch().

List fields

NameDescription
itemsThe 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

NameDescription
formPluginapp.use(formPlugin, { i18n, showErrors, keyPrefix }): defaults for every form.
provideFormConfigThe same defaults for one component tree.
useFormContextThe form of the nearest parent that called useForm, typed with useFormContext<typeof schema>().
useFielduseField(() => props.name): one field of the parent’s form, by name.
msgmsg(key, params?, fallback?): a message from your own catalog, for a schema or a rule.
validatorFrom vael-form/validator: a validate map as a Standard Schema.