Form Error Summary

A submit that fails into one summary of everything wrong, with each line a link to its field.

Build a form that fails into one error summary. Structure: a summary block above the fields, then the fields, then submit. On failed submit, render the summary and move focus. The rule everybody gets wrong: MOVE FOCUS TO THE SUMMARY, not to the first invalid field. Jumping straight into an input hides how many problems there are in total, and the count is exactly what someone needs before they start fixing anything. Give the summary tabIndex={-1} and focus it inside a requestAnimationFrame so it exists first. EVERY LINE IS A LINK to its field, moving focus there on click. A summary you cannot click is a list of complaints rather than a way through the form. Lead with the COUNT: "3 problems to fix", stated before the problems themselves. It sets the size of the job in one line. Show each error in TWO places: in the summary and under the field itself. The summary is for orienting, the inline message is for fixing, and neither one replaces the other. Accessibility, and here it is the whole point: - role="alert" on the summary - aria-invalid on each failing input - aria-describedby pointing at that field's inline message Without these, a failed submit is silent and the person is left hunting. Motion: the summary enters from y -6 with a fade, 220ms on ease [0.22, 1, 0.36, 1]. It has just pushed the form down, and moving with that push is what stops it looking teleported in. Under prefers-reduced-motion, use opacity only. The focus move and the announcement are untouched, because they ARE the component. Colors as tokens: your destructive token for the summary border, the count and the inline messages; surface and border for the fields. Use neutral placeholder values. Build the component, not this demo of it. - Ambient motion that IS the component may loop: a drifting background, a marquee, a spinner while something is genuinely loading. - Do not add any timer, interval, loop or script that performs a person's action by itself. No auto-hover, no auto-click, no cycling through states, no pretend submitting, no replaying the interaction on a schedule. - Every state that answers a person waits for a real event from that person. - Placeholder copy and sample content are welcome. Simulated behaviour is not.

Rate it
0
0

We'd like to measure how the site gets used, with Google Analytics. It sets cookies. Everything the site needs to work runs either way. How we handle data