Skip to main content
  1. Docs
  2. Components
  3. 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

form.tsx
// 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.

PropTypeDefaultWhat it does
onFormSubmit(values, details) => void—Runs only when every field is valid; values are keyed by name.
errorsRecord<string, string | string[]>—Server errors, keyed by each field's name.
validationMode"onSubmit" | "onBlur" | "onChange""onSubmit"When fields check themselves.
summarybooleantrueAfter a failed submit or server errors: the summary at the top, and focus.
summaryTitle · summaryHeadingLevelReactNode · 2–6"Fix these to continue" · 2The summary's heading.
ErrorSummary: items{ id?, message }[]requiredThe problems; id links to the control.
ErrorSummary: title · headingLevel · autoFocus…— · 2 · trueIts heading, and whether it takes focus as it appears.

03

Parts

Each part carries a data-slot, for tests and placement.

data-slotElementWhat 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.

invite.tsx
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>
Next — FormAccessibility