Flight Booker
UI Coding
Easy
20 min
forms
dates
validation
derived-state
Build a small flight booking form.
Requirements
- A Trip type select with two options: "One-way flight" (default) and "Return flight".
- A Departure date and a Return date, both
<input type="date">. Both default to today (in the user's local time zone). - The return date is disabled for one-way trips.
- Validation:
- The departure date can't be in the past.
- For return trips, the return date can't be before the departure date.
- Invalid dates get
aria-invalid="true"and a message linked witharia-describedby. Also set the nativeminattributes so the date picker greys out impossible days.
- The Book button is disabled while the form is invalid.
- Booking shows a confirmation in a
role="status"element:- "You booked a one-way flight departing 2026-12-01."
- "You booked a return flight departing 2026-12-01 and returning 2026-12-08."
Follow-up
- What goes wrong if you compute "today" with
new Date().toISOString().slice(0, 10)? - Should Book be disabled, or enabled with errors shown on click? Discuss the accessibility trade-off.
- How do you test date logic that depends on the current day?
Spotted a mistake or a rights concern? Report an issue