Form
Validates fields and displays server errors.
Installation
Install the following dependencies:
Set up the token layer and StyleX compiler from Installation, including state-styles.ts.
Copy and paste the following code into your project.
Update the import paths to match your project setup.
Usage
Anatomy
Form contains named Field controls and a submit button.
Server errors
Pass server messages through errors, keyed by field name. Edit the field to clear its error. Submit admin in the demo to receive a simulated server error.
API reference
Accepts Base UI Form props, including render, plus xstyle, className and inline style.
Form
| Prop | Type | Default |
|---|---|---|
errors | Record<string, string | string[]> | — |
validationMode | "onSubmit" | "onBlur" | "onChange" | "onSubmit" |
onFormSubmit | (values, eventDetails) => void | — |
actionsRef | RefObject<Form.Actions | null> | — |
onFormSubmit receives valid values and prevents native navigation. Name each Field to include it in the submitted values.
Data attributes
| Attribute | On | Effect |
|---|---|---|
data-slot="form" | form | Form anatomy |