Form
Bind schema fields, validation, submission, and reset through createForm.
The controls below configure the form.Field wrappers inside the form. To explore the label,
description, help, and error slots, use the Field playground.
Anatomy#
Each form.Field uses the Field layout; the bound form.Form owns only its
native form root.
Usage#
Use createForm for schema validation, submission, and reset. It returns a reactive Formisch store
with bound form.Form and form.Field components. Use standalone Field
when you only need labels and messages.
Submission#
form.Form renders Formisch’s Form: it prevents native navigation, validates the schema, focuses
the first invalid field in schema order, and calls onSubmit with the validated schema output
(after any Valibot transforms) and the native SubmitEvent. An invalid submit does not call
onSubmit. Native action and method attributes do not enable a browser navigation submit. The
returned store also supports Formisch’s public methods and helpers, including submit(form) and
programmatic field focus.
form.isSubmitting stays true until a promise returned by onSubmit settles. A thrown or
rejected error is stored in the form errors rather than propagating; an error without a message
is recorded as the unknownError translation. form.Form does not disable child controls during
submission, so derive button loading or disabled state from form.isSubmitting.
Root styling#
<form.Form> owns only its native form root, exposed as the root slot. Use class and style
(or classes={{ root }} and styles={{ root }}) for an individual form, or configure form.base.root
in your Theme. The root sets data-submitting while form.isSubmitting is true. Style the parts
of a field through the slot maps on form.Field.
Bound field outside the form root#
form.Field captures the Formisch store from createForm(), so it works without rendering
form.Form. Use the standalone Field when schema binding is not needed.
Field labels and messages#
<form.Field> accepts every Field prop except name, which takes a schema
path: label, hint, description, help, required, orientation, and so on. Its error is the
first schema error unless you pass error. Moraine controls link descriptions and error messages
through ARIA attributes.
Nested and array paths#
Target nested object and array fields with a path array such as ['profile', 'email'] or
['tags', 0]. Path types are validated and autocompleted from the schema. A dotted string like
'profile.email' is read as one top-level key, not a path.
Reset#
A type="reset" button restores the initial store input snapshot and clears validation metadata.
The restore runs in a microtask after the reset event and is skipped if a handler calls
event.preventDefault(). Handle onReset on form.Form when your code needs to react to it.
Examples#
Save a username#
Define a schema and initialInput, then render the bound form.Form and form.Field. Submit
receives the validated output.
Configure field copy#
Set label, hint, description, help, and required on form.Field. Pass error only when
the page or server supplies a message outside the schema.
Lay out a settings panel#
Set orientation="horizontal" so the label sits beside the control.
Edit nested profile fields#
Pass a path tuple such as ['profile', 'email'] when the schema nests objects.
Save a draft with loading#
Read form.isSubmitting for the submit button. The form does not disable nested controls on its
own.
Restore the initial snapshot#
A type="reset" button restores initialInput and clears validation metadata.
Validate name and email#
Schema messages surface on the bound field after submit or configured input validation.
Show a server error on a token#
Pass an application or server string to form.Field error={...} to force an error outside the
schema.
Change the control from field error#
Give form.Field a child render function to read { error } while the control still inherits the
bound field state.
Create a project with mixed controls#
Compose Input, Textarea, Select, and Checkbox in one schema-validated form.
API Reference#
Attributes#
data-submittingProps#
Form#
Renders a <form> element by default.