Sub topic 3
Saving Drafts and Resuming Later
You should know HTML form elements, basic TypeScript, and how a browser submits form data. A draft is a copy of what a user has entered so far. Saving drafts lets a user reload the page or return later and continue. Store drafts in sessionStorage for one browser tab, or on a server when they must last longer.
Save after each change, and store the current step with the values:
const DRAFT_KEY = "signup-draft";
function saveDraft(step: string, values: Record<string, string>): void {
sessionStorage.setItem(DRAFT_KEY, JSON.stringify({ step, values }));
}
function loadDraft(): { step: string; values: Record<string, string> } | null {
const raw = sessionStorage.getItem(DRAFT_KEY);
if (!raw) return null;
try {
return JSON.parse(raw);
} catch {
return null;
}
}The try block matters. Corrupt or outdated stored text should start a fresh form, not crash the page.
Making Forms and Step Changes Accessible
Give every field a visible label linked with for, and connect error text with aria-describedby:
<div>
<label for="email">Email address</label>
<input id="email" name="email" type="email" autocomplete="email" required
aria-describedby="email-error" aria-invalid="true">
<p id="email-error">Enter an email address in the format [email protected].</p>
</div>When the step changes, move focus to the new step's heading. Also announce the change in an element with aria-live="polite", such as "Step 2 of 3: Details".
The Review Step and Final Submission
The review step shows each active value as read-only text, with an Edit link for each step. Hidden conditional fields stay out of this list. Submit only after every step passes validation.
Handling Submission Failures and Duplicates
Keep the user's values when a request fails, and show the error where the user will see it. Disable the submit button while the request runs, and send a unique key with each attempt so a retry cannot create a second record.
| Failure | What to do |
|---|---|
| Network timeout | Keep values and show a retry button |
| Server validation error | Show the message beside the matching field |
| Double click | Disable the submit button while the request runs |
Testing the Flow and Measuring Drop-Off
Record an event when each step appears and when the user submits. The step where most users leave is the first one to fix. Also test the restore path by reloading in the middle of the flow and confirming the values and step come back.
Exercise
Exercise
Why does loadDraft return null when JSON.parse throws?
Show answer
Stored text can be corrupt or come from an older version of the form. Returning null starts a fresh form instead of crashing the page.
Exercise
Which event should you log to find where users abandon the flow?
Show answer
Log an event each time a step is shown, then compare the counts between consecutive steps to find the largest drop.