JavaScript AcademyProfessional Engineering

Level 3 · Interactive Web Applications Project 24 of 60 Runs in the browser

Project 24: Interactive Form Builder

Design a form from field definitions: add, reorder and remove fields, see a live accessible preview built with DOM methods, and export the definition as JSON.

Level 3 covers the DOM, events, forms, state and storage, so you write both files: the logic file holds pure state functions and app.js renders the state and handles events. Storage in the website's preview is memory-only; the downloaded project uses your browser's real localStorage.

1 · The problem

Event organisers keep asking for slightly different sign-up forms. A form builder lets them describe fields as data (type, label, required) and see the real form straight away. The preview must be accessible and must validate required fields, and the definition must be exportable as JSON.

User stories

  • As an organiser, I want to add 'Dietary needs' and see it in the form.
  • As an organiser, I want to put Email first.
  • As an organiser, I want to save the design and load it later.

2 · Requirements

  • Add a field with a type (text, email, number, checkbox), a label and a required flag; reject empty or duplicate labels.
  • Move a field up or down and remove it.
  • Render the field list with Up, Down and Remove buttons (disabled at the ends).
  • Build the preview with createElement: every input has a <label for> and required fields are marked.
  • On preview submit, report missing required fields.
  • Export the definition as formatted JSON and import it back, rejecting invalid JSON.

Acceptance criteria

  • The builder starts with Name and Email; the preview has two labelled inputs.
  • Adding 'Age' (number) adds a third field.
  • Moving Email up makes it first in the preview.
  • Submitting the empty preview reports 'Missing: Name, Email'.

Architecture

LayerFileResponsibility
Pageindex.html + style.cssField form, field list, preview and JSON box.
Statebuilder.jsAdd, move, remove, slug ids, import validation. Your work.
View and eventsapp.jsField list, preview, events, export and import. Your work.

Flow: Builder events → fields = addField / moveField / removeField(fields, …) → renderFields() + renderPreview(); preview submit → missing required; Export → JSON.stringify; Import → parseDefinition

Expected result

Interactive Form Builder: finished app
finished app

Screenshots are captured automatically from the solution by the browser test suite.

Build it: guided stages

Pick a stage, load its starter files, follow the steps, then run the app and the tests. Every stage is preserved separately, so loading one never overwrites another.

  1. Stage 1: Render from definitions · Draw the field list and build the preview with DOM methods.
  2. Stage 2: Add, move and remove · Edit the definition with a form and delegated buttons.
  3. Stage 3: Validate and export · Check the preview's required fields and save the design as JSON.

Troubleshooting

Clicking a label does not focus its input.
Set label.htmlFor to the input's id.
Up and Down buttons stop working after a change.
They are rebuilt on every render; listen on #fields, not on each button.
Import accepts nonsense.
Check the parsed value is an array of complete field objects before using it.

Extension challenges

  1. Add a select field type with options.
  2. Add placeholder text to fields.
  3. Store the design in localStorage.

Downloads

Browser projects open directly from index.html. Node.js unit tests: run node --test in the project folder.

AI development prompts

Context: I am building the academy's Interactive Form Builder. Task: explain why every generated input needs a matching label element. Constraints: explain the idea and point to the line that matters; do not write the whole solution. Expected behaviour: I can finish the stage myself. Testing: suggest two inputs that would show whether my code is right.
Context: My Interactive Form Builder passes the visible tests. Task: check my import validation for data that could break the preview. Constraints: do not rewrite my code; list issues in order of importance. Expected behaviour: I understand each issue and can fix it. Testing: give one test case per issue.
Context: I finished the Interactive Form Builder. Task: help me plan this extension: add a select field type. Constraints: keep the logic file free of page code; existing tests must still pass. Expected behaviour: a short plan with the functions to add or change. Testing: describe the new tests I should write first.

Source

Repository folder: projects/project-24-interactive-form-builder/ · view on GitHub