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.
