Command Palette

Search for a command to run...

Hectal
Phase 5: Forms and User Input
React · Exercise 5 of 5 Previous
Advanced

Mini build: a contact form that sends

Build a working contact form with a name input (id="name", name="name"), a message textarea (id="message", name="message") and a submit button (id="send").

On submit, validate: the name is required (Enter your name. in p#name-error) and the message needs at least 10 characters after trimming (Write at least 10 characters. in p#message-error). Errors appear after the first submit and update as the user types. Invalid fields get aria-invalid="true". Nothing is sent while there are errors.

When valid, send with the provided fakeSend (it takes 300 ms). While sending, the button is disabled and reads Sending…. Afterwards show <p id="status">Message sent!</p>, empty both fields, hide the errors, and put the button back to Send.

What Check tests

  1. An empty submit shows both errors and sends nothing
  2. Invalid fields are marked with aria-invalid
  3. Errors update as the user types
  4. While sending, the button is disabled and says Sending…
  5. After sending: success message, empty fields, button back to Send

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.