Appica UIUI 1.0.0

Form

A form that validates its fields on submit and shows server errors.

Usage

Form renders a native <form> and ties together the Fields inside it. On submit it validates every field, focuses the first invalid one, and only calls onFormSubmit — with the collected { name: value } map — once they all pass. preventDefault() is handled for you when you use onFormSubmit.

It also closes the loop on server-side validation: pass an errors object keyed by field name and each matching Field shows the message through its FieldError, no extra wiring. Use validationMode to choose when fields validate (onSubmit, onBlur, or onChange); a validationMode set on an individual Field wins over the form's.

Examples

Default

Give each Field a name and the values arrive in onFormSubmit as an object keyed by those names. The form handles preventDefault itself.

Validation

Validate on submit and reject the attempt when something's off. Here the handler builds an error map, marks each offending Field invalid, and shakes just those fields with the animate-shake utility so the ones needing attention nudge into view — the valid fields and the button stay put. Once a field has been flagged, it re-validates on every keystroke using the same rules — so the message clears the moment the value becomes valid (and updates if it's still wrong), instead of lingering until the next submit. noValidate hands validation to your code instead of the browser's native bubbles.

Server-side errors

When validation lives on the server, pass its response to the errors prop keyed by field name. The matching Field renders the message through its FieldError, and the error clears as the user edits the field. (Submit taken@example.com to see it.)

RTL

Every Appica UI component supports right-to-left layouts out of the box. Set the dir attribute on a container (commonly your <html> element) so CSS logical properties resolve correctly, and wrap your tree in DirectionProvider so direction-aware behavior — roving focus, popup placement, and the like — follows the same direction.

Labels, controls, and messages all align to the start edge and follow the resolved direction. For setup details and caveats, see the RTL guide.

API reference

Form wraps Base UI's Form and renders a native <form>, so every standard form attribute (onSubmit, noValidate, action, method, ref, …) passes straight through alongside the props below.

Accessibility

  • Renders a native <form>, so browser submit semantics (Enter to submit, <button type="submit">) work as expected. Name it with aria-label / aria-labelledby if it isn't already introduced by a heading.
  • On an invalid submit the first invalid field receives focus, so keyboard and screen-reader users land on the problem.
  • Validation messages come from each Field's FieldError, which is wired to its control for assistive tech — see the Field page for the per-control accessibility details.
  • The animate-shake feedback in the validation example is purely visual; it conveys nothing on its own, so the error message remains the source of truth.

© 2026 Appica UI. A free component library, crafted by the Appica team.