Time picker
Every <input type="time" class="form-control"> becomes a field you can simply type in — "930", "9:30 pm", "21:30" all work — with a list of times to pick from. On phones the list opens as a bottom sheet with big rows. datetime-local becomes a date field and a time field side by side. Nothing to switch on.
<div class="field max-w-xs">
<label class="form-label" for="tp-basic">Pickup time</label>
<input class="form-control" type="time" id="tp-basic" name="pickup" value="09:30">
</div>
How it works
- Write a normal time input with the
form-controlclass, a label and a name — exactly as you would for the browser's own. - Moey adds the Moey field in front of it and hides the real one, which stays in your form: it still has the name,
required,min,maxandstep, and its value is alwaysHH:MM(24-hour), ready to send to a server. - Listen on the real input — it fires
inputandchangewhenever the time changes, typed or picked.
Steps, earliest and latest
step (in seconds, like the browser's) sets the list's spacing — 900 for every 15 minutes, 3600 for whole hours; 30 minutes by default. min and max keep the list to opening hours, and a typed time outside them is flagged.
<div class="field max-w-xs">
<label class="form-label" for="tp-hours">Delivery slot</label>
<input class="form-control" type="time" id="tp-hours" step="900" min="09:00" max="18:00">
<div class="form-text">Every 15 minutes, 9:00 to 18:00</div>
</div>
12- or 24-hour
The clock follows the page's language (<html lang>): "9:30 PM" in American English, "21:30" in most other places. Choose with data-moey-clock="12" or "24" on the input or any parent. The value sent with the form is 24-hour either way.
<div class="field max-w-xs">
<label class="form-label" for="tp-24">Start (24-hour)</label>
<input class="form-control" type="time" id="tp-24" data-moey-clock="24" value="21:15">
</div>
In a form, with validation
required works as usual: an empty field stops the form, is marked, and gets the focus. Something that isn't a time ("lunch") is marked too, with "Enter a time, like 9:30".
<form class="stack gap-3 max-w-xs" id="tp-form" novalidate>
<div class="field">
<label class="form-label" for="tp-req">Call me at</label>
<input class="form-control" type="time" id="tp-req" name="call" required>
<div class="form-error"><i class="mi mi-circle-alert"></i>Pick a time for the call.</div>
</div>
<div><button class="btn btn-default" type="submit">Book the call</button></div>
</form>
Date and time
<input type="datetime-local" class="form-control"> becomes a Moey date field and a time field side by side; the real input keeps the combined value (2026-12-01T08:00).
<div class="field max-w-md">
<label class="form-label" for="tp-dtl">Send the newsletter</label>
<input class="form-control" type="datetime-local" id="tp-dtl" name="send_at" value="2026-12-01T08:00" step="1800">
</div>
Example: a meeting
Day, from and to — with the length worked out as you change them.
<div class="grid sm:grid-cols-3 gap-3">
<div class="field"><label class="form-label" for="day">Day</label><input class="form-control" type="date" id="day"></div>
<div class="field"><label class="form-label" for="from">From</label><input class="form-control" type="time" id="from" step="900"></div>
<div class="field"><label class="form-label" for="to">To</label><input class="form-control" type="time" id="to" step="900"></div>
</div>
<script>
const mins = (v) => { const [h, m] = v.split(':'); return h * 60 + +m; };
form.addEventListener('change', () => {
const length = mins(to.value) - mins(from.value);
to.setCustomValidity(length > 0 ? '' : 'Ends before it starts');
});
</script>
On a phone
Tapping the field opens the list as a bottom sheet (no keyboard needed); drag it down or tap outside to close.
What you can type
| Typed | Becomes |
|---|---|
9 · 09 | 9:00 |
930 · 0930 · 9:30 · 9.30 · 9 30 | 9:30 |
9:30pm · 9.30 p.m. · 930p | 21:30 |
12am · 12pm | 0:00 · 12:00 |
2130 · 21:30 | 21:30 |
| (empty) | No time (or "required" if it must have one) |
Keyboard
↓ / ↑ open the list and move through it (Page Down / Page Up jump an hour at 15-minute steps), Enter picks, Esc closes, and typing goes straight into the field. The list starts on the chosen time — or the one nearest to now. Screen readers hear a combobox with its options.
Reference
| On the input | What it does |
|---|---|
input[type="time"].form-control | Becomes a Moey time field (automatic) |
input[type="datetime-local"].form-control | Becomes a Moey date field + time field |
step · min · max | The list's spacing in seconds (1800) · earliest · latest |
data-moey-clock="12|24" | The clock (else from the page's language) |
data-moey-native | Keep the browser's own time input |
Events input · change | On the real input, whenever the time changes |
Moey.timepicker(input) | { open(), close(), value } (value: "HH:MM", settable) |