StaffCoder
TypeScript
Vanilla TypeScriptTypeScript 7.0
6 modules · 24 challengesSign up
Module 3 · Forms & Input Handling

Profile Settings Editor

easyBaseline vs. current diffing to drive dirty state—No data yet

Problem statement

A profile page that starts out already filled in and only lets the person save once they have actually changed something. The Save button stays off while the form matches what was there on load, and turns back off the moment things go back to matching. Reset snaps everything back to how it was, and the browser only asks "are you sure?" when there are still unsaved changes.

Demo

The page, styles, the pre-filled fields, message spots, Save button, Reset button and success banner are already scaffolded and wired. Only the isDirty function in src/js/dirty.ts, the validate function in src/js/validation.ts, and the renderValues, renderFieldError, renderSaveEnabled and renderSavedFlash functions in src/js/render.ts are missing — implement them so every test passes. Do not edit any other file.

What to implement

  • On load, show the three starting values in the three fields, keep the Save button switched off, keep the success banner hidden and keep every reminder spot next to a field empty.
  • When the person changes any field so it no longer matches the starting value, turn the Save button on; when they change it back so it matches again, turn it off.
  • Hide the success banner as soon as the person starts editing again, so it never lingers next to changes that have not been saved.
  • When the person clicks Save and something is wrong, show a short reminder next to any field with a problem and keep the Save button on.
  • When the person clicks Save and everything is fine, remember these values as the new starting point, turn the Save button off, clear every reminder and show the success banner.
  • When the person clicks Reset, put every field back to the current starting values, wipe every reminder, hide the success banner and turn the Save button off.
  • While the form has unsaved changes, make the browser show its built-in "leave this page?" prompt if the person tries to navigate away, and let them leave silently when there are no unsaved changes.
  • Everything shown must come from the starting values you were given and the current values on the page — nothing should be hardcoded.

More in Forms & Input Handling

See the module
Insurance Quote Form Implement visibleFieldNames, validate, renderGroups, renderFieldError, and renderPayload. The insurance-type select reveals one of three groups (Auto / Home / Life); switching type clears the previously visible group's inputs; validation reports errors only for currently visible fields; a valid submit renders a JSON payload with the common fields plus the visible group's fields only.0%0 of 1 solvedeasyMember Signup FormImplement validate and the renderFieldError, renderSubmitEnabled, renderSuccess helpers. Errors appear only after a field is blurred, aria-invalid and aria-describedby toggle in lockstep with the message, the submit button tracks live validity across name / email / password (min 8) / confirm, and mismatch is reported on the confirm field only. A valid submit clears the form, re-disables submit, and reveals the success0%0 of 1 solvedeasyStudio Booking SubmissionImplement validate, buildPayload, and the renderFieldError, renderFormDisabled, renderSubmitError, renderConfirmation helpers. On submit, the form validates, normalises raw inputs (trimmed strings, numeric fields as number, ISO date passthrough), disables every input while awaiting window.submitBooking(payload), and either reveals a confirmation with the returned reference or re-enables the form and surfaces the rejection message with typed values preserved.—No data yeteasy

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.