Patterns
Didactika theme v0.1A form page
How a long form is organised so it can be filled in without getting lost, with validation next to each field.
A form page asks for data once and well. It is a card with a title, the fields in the order in which people think of them, and the actions at the foot.
When to use it
- Creating or editing one object with more than two or three fields.
- For a single field, or a choice of two, use a dialog or an inline control instead.
- For a long task whose order matters, use a guided flow.
Anatomy
- Title and the rule for required fields, said once (“Fields marked with * are required”).
- Fields, one per row, each with its label above, the field, and its help under it.
- Pairs that belong together (first and last name, from and to) side by side when they fit.
- Sections with a title each when the form is long; a section is a card or a titled group.
- Foot: the main action on the right named by what it does (“Create course”); Cancel before it.
A form with its validation states
This Moodle version has no dark mode: examples stay light.
Layout and spacing
| Between | Distance |
|---|---|
| Fields | 1.25 rem |
| Label and field | 0.375 rem |
| Field and its help or error | 0.375 rem |
| Sections | 2 rem, with the section title above its fields |
| Last field and foot | The foot is separated by a hairline |
Fields take the full width of the column up to 42 rem; a text that is short by nature (a postcode, a number) has the width of its content.
Behaviour
- Validate when leaving a field and again on sending. While typing, only clear an error that is already shown.
- On sending with errors, move the focus to the first error and show an alert at the top that lists them, each one linking to its field.
- The main button is disabled while sending, with a small spinner and the text “Saving…”. It is never disabled before, because a disabled button hides the reason.
- After saving, go to where the user was (the list, the detail) with a toast that says what was saved; stay in the form only if the next step is more editing.
- If the user leaves with unsaved changes, ask once, in a dialog with “Discard” and “Keep editing”.
States
| State | What the user sees |
|---|---|
| Sending | The main button disabled with a spinner and “Saving…” |
| Saved | A toast with the result, or the page the user goes to next |
| Error | An alert that lists the errors and links to each field; the errors by their fields, in text |
| Locked | A field the user cannot change is disabled and says why in its help |
Narrow screens
Pairs stack; the foot’s buttons take the full width, the main one first (above). Labels never go to the left of the field.
Accessibility
- Every field has a visible
label, tied to it; help and errors are tied witharia-describedby. - A required field is marked in the label and with
required. - The error is text; the red border is only a support. Never use a placeholder as a label.
- The foot is reachable after the last field in the tab order.
Before shipping
- Every field has a label, help if needed, and an error message written.
- The first error receives the focus.
- The main button says what it does.
- Leaving with changes asks.
UI