- Docs
- Components
- Forms
Form
Fields that check themselves on submit, server errors by name, and a summary of what to fix.
- Import
- @qeetrix/react/experimental
- Status
- ExperimentalSince 0.0.6
- Renders
<form>Server-rendered- Tested
- WCAG 2.2 AAaxe on every pull request
01
Import
// Experimental: from the package's experimental entry, until it's stable.
import { Form, ErrorSummary } from "@qeetrix/react/experimental";02
Props
And every native attribute of the element it renders.
| Prop | Type | Default | What it does |
|---|---|---|---|
onFormSubmit | (values, details) => void | — | Runs only when every field is valid; values are keyed by name. |
errors | Record<string, string | string[]> | — | Server errors, keyed by each field's name. |
validationMode | "onSubmit" | "onBlur" | "onChange" | "onSubmit" | When fields check themselves. |
summary | boolean | true | After a failed submit or server errors: the summary at the top, and focus. |
summaryTitle · summaryHeadingLevel | ReactNode · 2–6 | "Fix these to continue" · 2 | The summary's heading. |
ErrorSummary: items | { id?, message }[] | required | The problems; id links to the control. |
ErrorSummary: title · headingLevel · autoFocus | … | — · 2 · true | Its heading, and whether it takes focus as it appears. |
03
Parts
Each part carries a data-slot, for tests and placement.
| data-slot | Element | What it is |
|---|---|---|
form | <form> | Fields stand space.form-gap apart. |
error-summary | <div> | The summary. |
error-summary-list | <ul> | Its links. |
04
Server errors by name
Return the server's errors as { name: message }: each lands on its field and in the summary.
const [errors, setErrors] = useState<Record<string, string>>({});
<Form
errors={errors}
onFormSubmit={async (values) => {
const result = await invite(values);
if (!result.ok) setErrors(result.errors); // { email: "priya@acme.in is already a member." }
}}
>
…
</Form>