Time picker
Pick the hour and the minutes separately, or just type a time. 12-hour and 24-hour clocks. The field shows a friendly time; the form gets a plain HH:MM.
Pick or type
Put the input in .time. A tap opens three columns: hour, minutes, AM / PM. Each tap changes just that part, so 9:30 PM is three taps and changing the minutes later is one. Typing works too: 9, 930, 9:30p, 21:30 and noon are all understood and tidied when you leave the field.
<div class="cluster gap-4 items-end">
<div class="form-field w-48">
<label class="form-label" for="t-1">Start</label>
<div class="time"><input class="form-control" id="t-1" name="start" data-format="12"></div>
</div>
<div class="form-field w-48">
<label class="form-label" for="t-2">End</label>
<div class="time"><input class="form-control" id="t-2" name="end" value="17:00" data-format="12"></div>
</div>
</div>12 or 24 hours
data-format="12" shows 1 to 12 with an AM / PM column. data-format="24" shows 00 to 23 and no AM / PM. Leave it out and it follows the page's language (<html lang>). Either way, the form gets the same HH:MM.
<div class="cluster gap-4 items-end">
<div class="form-field w-48">
<label class="form-label" for="t-5">12-hour</label>
<div class="time"><input class="form-control" id="t-5" data-format="12" value="21:30"></div>
</div>
<div class="form-field w-48">
<label class="form-label" for="t-4">24-hour</label>
<div class="time"><input class="form-control" id="t-4" data-format="24" value="21:30"></div>
</div>
</div>Step and limits
data-step is the minutes between choices in the minutes column (default 5: 00, 05, 10 ...). data-min and data-max keep it inside opening hours: hours and minutes outside them are greyed out, and a typed time outside them is flagged.
9 AM to 5 PM, every 15 minutes
24-hour clock, on the half hour
<div class="cluster gap-4 items-end">
<div class="form-field w-48">
<label class="form-label" for="t-3">Appointment</label>
<div class="time"><input class="form-control" id="t-3" data-format="12" data-step="15" data-min="09:00" data-max="17:00"></div>
<p class="form-hint">9 AM to 5 PM, every 15 minutes</p>
</div>
<div class="form-field w-48">
<label class="form-label" for="t-6">Departure</label>
<div class="time"><input class="form-control" id="t-6" data-format="24" data-step="30"></div>
<p class="form-hint">24-hour clock, on the half hour</p>
</div>
</div>Notes
- The field's
namemoves to a hidden input that holdsHH:MM(24 hours), so the server always gets the same format. It fireschangewhen the time changes. - Keyboard: Down arrow in the field moves into the hour column. Up / Down move in a column, Left / Right (or Tab) go to the next column, Enter or Space picks, Esc goes back to the field.
- Now sets the current time (on the step, inside the limits). Done closes the panel; so does a tap outside.
Momo.time.parse("9:30p")gives minutes after midnight (1290),Momo.time.format(1290)gives "9:30 PM".