- 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
Checked on submit
Send it empty: the summary lists what to fix, in each field's own words, takes focus, and links to each field.
<Form onFormSubmit={(values) => invite(values)}>
<TextField label="Full name" name="name" validate={(value) => (value ? null : "Enter their full name.")} />
<TextField label="Work email" name="email" type="email" validate={(value) => (value.includes("@") ? null : "Enter a work email, like priya@acme.in.")} />
<RadioGroup label="Role" name="role" defaultValue="member">
<Radio value="member" label="Member" />
<Radio value="admin" label="Admin" />
</RadioGroup>
<Button type="submit" icon={Next}>Send invite</Button>
</Form>02
Server errors
errors, keyed by each field's name: they show on the field and in the summary.
const [errors, setErrors] = useState({});
<Form errors={errors} onFormSubmit={async (values) => setErrors(await invite(values))}>
<TextField label="Work email" name="email" type="email" required />
<Button type="submit" icon={Next}>Send invite</Button>
</Form>03
The summary on its own
ErrorSummary: a danger alert with a heading, each item worded as its field's error and linked to it.
Error:
Fix these to continue
- Enter a work email, like priya@acme.in.
- Choose a role.
<ErrorSummary
autoFocus={false}
items={[
{ id: "email", message: "Enter a work email, like priya@acme.in." },
{ id: "role", message: "Choose a role." },
]}
/>