FRM-003 Give every form in a dialog a Cancel that always works and changes nothing
- Level
- Rule
- Verdict
- Unanimous (3 of 3)
- Area
- Forms
- Status
- decided, version 1.0.3
Rule
Every form in a dialog, sheet or other modal view has a visible Cancel button that is always enabled, is never blocked by field errors, sends nothing and leaves everything as it was before the form opened.
Examples
Live examples built with Justified's components. Try them with the mouse, the keyboard or a screen reader.
Do: Cancel works while a field shows an error
Change delivery address
Don't: Cancel greyed out until the form is valid
Change delivery address
Why
A modal form blocks the rest of the screen. If the only way out is to finish the task, the person is stuck: they must send something they may not want, or reload and hope. A Cancel that is always there, always works and changes nothing turns opening a form into a safe thing to try. No WCAG criterion asks for a Cancel. A way out that commits nothing shares the aim of WCAG 2.2, 3.3.4 Error Prevention (Legal, Financial, Data), and a Cancel button that can be reached with Tab is the plainest keyboard way out of a modal form, which supports 2.1.2 No Keyboard Trap. This rule supports both and is required by neither.
Do
- A dialog Change delivery address has Cancel and Save address. Cancel closes the dialog, and the order keeps the old address.
- A dialog New category keeps Create unavailable until a name is typed, and the text "Enter a name to create the category." sits just before the button, as ACT-005 asks. Cancel works the whole time.
- A dialog Edit theme previews the new colour on the page while the person picks it. Cancel puts the old colour back, so the page looks just as it did before the dialog opened.
- Phone shows the error "Enter a phone number with at least eight digits". The person presses Cancel. The error does not stop it. Whether a question about the typed input comes first is decided by FRM-004a in a full-screen dialog and by the guideline FRM-004b in a smaller one.
- The first step of a multi-step dialog Add user shows Cancel next to Next.
- Build Cancel as
<button type="button">, never as a submit button, so it cannot send the form even by accident. Give it less emphasis than the main action and keep it in the same place in every dialog. The order in code matches the order on screen, as LAY-002 says. - FRM-004a covers what happens before unsaved changes in a full-screen dialog are thrown away, and the guideline FRM-004b covers dialogs and sheets that do not fill the screen.
- When a form dialog also has a close icon that throws the input away, the icon does what Cancel does and has the same accessible name, Cancel. Close would promise that nothing is lost, as ACT-001a says. This is our own point.
- Escape does what Cancel does, as DLG-001 says.
- Our own choice, made to fit FRM-002b and outside the verdict: when the person moves from a field to Cancel or the dialog's close control, hold back that field's check. This covers Tab and a pointer press alike. A click on Cancel takes focus off the field before the click lands, and in Safari a clicked button does not take focus, so start the hold-back on the press, not only on focus. If focus then moves on to anything other than closing the dialog or its discard question, such as Save or back to a field, run the check at once, as FRM-002b says. The hold-back applies only to Cancel and the close control, never to other buttons. For example, the person types "12" in Postcode and tabs to Cancel: no error appears. They tab on to Save: the error appears on Postcode.
Don't
- Offer only Save in a dialog, so the only way out is to save.
- Grey out Cancel until the form is valid, or while fields show errors.
- Let Cancel save part of the form, such as a file the person already attached.
- Leave a preview or a toggle in place after Cancel, so the page no longer looks as it did.
- Show "Enter a valid email address" on Email, where the person typed "anna@", because they moved from it to Cancel.
- Label the way out Close in one dialog and Cancel in the next, when both throw the input away.
Exceptions
- Modal forms only. This rule covers forms in dialogs, sheets and other modal views. It says nothing about forms on a page. Leaving a page with unsaved changes is the guideline FRM-004c.
- Later steps of a multi-step dialog. This rule covers a single-view modal form and the first step of a multi-step one. What later steps offer as a way out is outside this rule.
- Non-modal panels. A side panel that leaves the page usable is not a modal view and is outside this rule.
- Dialogs that are not forms. A dialog that confirms a destructive action follows DLG-003, which also asks for Cancel.
- While sending. Once the person has pressed the main action and the dialog shows progress, such as "Saving …", the form has been sent. This rule then no longer decides what Cancel does. STA-005a covers that moment. Its own choice is that Cancel either stops the request, with the input kept and a line that says what happened, or is unavailable until the reply.
Verdict
Unanimous (3 of 3). Only the judges decide; the expert witnesses are shown but do not vote. How verdicts work
| Source | Role | Stance | Page |
|---|---|---|---|
| WCAG 2.2 | Law | Supports | 3.3.4 Error Prevention (Legal, Financial, Data) |
| WCAG 2.2 | Law | Supports | 2.1.2 No Keyboard Trap |
| Material Design | Judge | Supports | Dialogs: guidelines |
| Apple Human Interface Guidelines | Judge | Supports | Sheets Modality Buttons |
| Carbon Design System | Judge | Supports | Forms Modal: usage Dialogs Button: usage |
| GOV.UK Design System | Expert witness | No position | |
| Nielsen Norman Group | Expert witness | Supports | Cancel vs Close: Design to Distinguish the Difference, by Aurora Harley Modal & Nonmodal Dialogs: When (& When Not) to Use Them, by Therese Fessenden |
Each stance links to the page it rests on, read on the date in the source register. This page never repeats what a source says; read the source itself.
History
- Version 1.0.3, : Refers to FRM-004c for leaving a page with unsaved changes.
- Version 1.0.2, : Refers to FRM-004b for dialogs that do not fill the screen and to STA-005a for the time while sending. Names the close icon in a form dialog.
- Version 1.0.1, : Examples in English.
- Version 1.0.0, : First version.
Last checked against the other rules for conflicts on .
More in Forms: 15 rules and 12 guidelines · All rules
Justified is an independent project. It is not affiliated with, sponsored or endorsed by the organisations whose guidance it cites. Read the full statement.
Apple is a trademark of Apple Inc., registered in the U.S. and other countries and regions.