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

Studio Booking Submission

easyPayload normalisationAsync submit lifecycle—No data yet

Problem statement

A studio booking form that has to be checked before it is sent, whose values have to be tidied up into a clean payload with the right kinds of data, and that has to actually send that payload to a booking service the environment provides. If the service says the booking went through, show the reference it returns. If the service says no, let the person try again with what they had already typed still in the form.

Demo

The page, styles, form markup, message spots, submit button, error banner and confirmation banner are already scaffolded and wired. A booking service is provided for you by the environment — you only need to call it. Only the validate function in src/js/validation.ts, the buildPayload function in src/js/payload.ts, and the renderFieldError, renderFormDisabled, renderSubmitError and renderConfirmation functions in src/js/render.ts are missing — implement them so every test passes. Do not edit any other file.

What to implement

  • When the person tries to submit, show a short reminder next to any field that is empty or wrong, and do not send the booking at all until every field is fine.
  • When every field is fine, tidy the typed values into a clean payload — no extra spaces around text, numbers as actual numbers rather than text, and the chosen date as a plain date.
  • Send that clean payload to the booking service exactly once per submit — never twice for the same click.
  • While the booking service is thinking, switch off the whole form so nothing can be edited or resubmitted mid-flight.
  • When the booking service comes back with a yes, show a confirmation banner with the reference it gave back.
  • When the booking service comes back with a no, show a red banner with the reason it gave, switch the form back on, and leave every value the person typed exactly where it was.
  • Everything shown must come from the values the person typed and from what the booking service returns — 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 solvedeasyProfile 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 solvedeasy

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.