Flight date form validating one-way and return bookings
Build the date step of an airline booking form. The traveller picks a one-way or a return flight, chooses the dates, and presses Book. The form must stop them from booking dates that make no sense, and confirm the booking on screen when the dates are valid.
<select> labelled Trip type with two options:
value="one-way", text “One-way flight” (selected at first)value="return", text “Return flight”<input type="date"> fields labelled Departure date and Return date. Both start at today, written as YYYY-MM-DD in the user’s local time zone. (toISOString() uses UTC, so it can be a day off.)<button> labelled Book. It is disabled while the form is invalid.Departure date cannot be in the past.Return date cannot be before the departure date. Returning on the same day is allowed.When the traveller presses Book on a valid form, show a confirmation:
Booked a one-way flight on 2026-11-14.Booked a return flight from 2026-11-14 to 2026-11-20 (6 nights). Use 1 night (singular) for one night and 0 nights for a same-day return.Changing any field after booking hides the confirmation, because it no longer matches the form.
Today is 2026-11-10.
Trip type Departure Return Book Message
one-way 2026-11-10 2026-11-10 enabled (none)
one-way 2026-11-20 2026-11-10 enabled (none, return date is ignored)
one-way 2026-11-09 2026-11-10 disabled Departure date cannot be in the past.
return 2026-11-14 2026-11-12 disabled Return date cannot be before the departure date.
return 2026-11-14 2026-11-14 enabled (none) -> Book shows "(0 nights)"
return 2026-11-14 (empty) disabled (none)
YYYY-MM-DD strings sort in date order, so a string comparison works.The tests fix the browser clock at noon on 2026-11-10, then fill in the form and read the text on screen like a user would. You don’t need test ids, specific class names, or an exact HTML structure. They check that:
<label>, or aria-label). The select uses the option values one-way and return.disabled property follows the trip type.disabled property follows the validation rules.