Form
Submit related fields and display validation feedback.
Installation
pnpm dlx shadcn@4.18.0 add @siteplane/formComplete the one-time setup first. Registry JSON lists source files and dependencies.
For this page’s examples, also install:
pnpm dlx shadcn@4.18.0 add @siteplane/button @siteplane/fieldset @siteplane/input @siteplane/selectUsage
import { Form } from "@/siteplane/components/form";
<Form onSubmit={(event) => event.preventDefault()}>...</Form>;Composition
Form
├── Field
│ ├── FieldLabel
│ ├── Input
│ └── FieldError
└── Button type="submit"Server validation
Pass errors keyed by Field name to show the errors your server returns. FieldError displays them, focus moves to the first field with an error, and a field's error clears as soon as its value changes. In this example a simulated request rejects the handle admin, and the submit button shows loading while the request runs.
Controlled reset
Native reset does not reset React state. Restore controlled values in onReset.
The validation resets with the form. A reset button or form.reset() returns every Field to how it was before the first submit: an error collapses, the field is no longer marked touched or dirty, and the errors you passed to Form clear until you pass new ones. The form validates again on its next submit.
Floating labels
Set labelPlacement="floating" on each Field for a compact form whose labels sit inside the fields, such as an address form. See Field for the supported controls. Every field but VAT ID is required and marked with requiredIndicator. With validationMode="onBlur" on the Form, a field left empty turns invalid and shows its message in the error tooltip when you return to it, and a submit moves focus to the first invalid field.
API reference
Form renders Base UI Form and adds data-slot="form"; on a native reset it clears the errors it was given. It adds no props of its own and accepts string className and all Base UI Form props.
| Prop | Type | Default | Description |
|---|---|---|---|
validation | onSubmit | onBlur | onChange | onSubmit | Form-wide validation timing, overridden per Field. |
errors | Record<string, string | string[]> | unset | External messages keyed by Field name. A native reset clears them until you pass a new object. |
on | FormEventHandler | unset | Native submission event; prevent default navigation for a local handler. |
on | (values, eventDetails) => void | unset | Foundation submission callback; automatically prevents the native submit default. |
on | FormEventHandler | unset | Reset application-owned controlled state here. Prevent the default to keep the values and the validation. |
actions | ref | unset | validate() validates all fields; validate(name) validates one. |
FormPrimitive exposes the foundation component. The Siteplane UI wrapper uses
its default Props type rather than adding a separately generic wrapper. Native
action/method, refs and composition are inherited. There is no built-in network
request, pending, success or error recovery service.
Usage notes
Use type="submit" deliberately: ordinary kit Buttons default to button. Validate again at the server before persistence. Async Field.validate does not prevent onSubmit submission; awaiting a server check belongs in your submission handler.