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

Insurance Quote Form

easyDeriving visible field sets from a discriminant and scoping validation0%0 of 1 solved

Problem statement

A quote form with a few common fields at the top and three sets of extra fields below — one for each kind of insurance. Only the set that matches the currently picked kind should be on the page, and only its fields should count when the person tries to submit or when the submitted values are shown back.

Demo

The page, styles, common inputs, the type picker, three sets of extra fields, message spots, submit button and the result panel are already scaffolded and wired. Only the visibleFieldNames function in src/js/groups.ts, the validate function in src/js/validation.ts, and the renderGroups, renderFieldError and renderPayload functions in src/js/render.ts are missing — implement them so every test passes. Do not edit any other file.

What to implement

  • Show only the set of extra fields that goes with the currently picked kind of insurance, and keep the other two sets off the page.
  • When the person changes the picker to a different kind, swap in the new set and empty out every field in the set that is going away.
  • When the person changes the picker, also clear any messages that were showing next to fields and hide the result panel from any previous submission.
  • When the person tries to submit, show a short reminder next to any of the currently visible fields that has a problem, and never show a reminder next to a field that is not on the page.
  • When the person tries to submit and everything visible is fine, show a result panel with the common values and the values of the currently visible extra set — never with values from a set that is hidden.
  • If the page loads with a kind already picked for the person, show that kind's set of extra fields straight away, with the picker already showing that kind.
  • The set of extra fields that goes with a kind is fixed: leave the common fields at the top always visible, and only add or remove the extra set below them.
  • Everything shown must come from the values on the page and the currently picked kind — nothing should be hardcoded.

More in Forms & Input Handling

See the module
Profile Settings Editor Implement isDirty, validate, and the render helpers (renderValues, renderFieldError, renderSaveEnabled, renderSavedFlash). Save enables the moment values diverge from the baseline and disables when they match again; a valid save promotes current values to the new baseline; Reset restores the baseline; and the browser's beforeunload prompt fires only while the form is dirty.—No data yeteasyMember 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.