Single, Range and Multiple Date Selection
calendar.mode sets what @pglejzer/datepicker-ui, the companion of timepicker-ui, lets the user select. getValue() returns a different shape for each mode.
Selection modes
#calendar.mode is "single" (the default), "range" or "multiple".
| Mode | getValue() returns | setValue() accepts |
|---|---|---|
"single" | DateValue or null | Date, ISO string "2025-03-14", null |
"range" | { start: DateValue, end: DateValue } or null | { start, end } of dates, null |
"multiple" | DateValue[] (sorted) or null | an array of dates, null |
DateValue has three fields. getValue() returns null when nothing is committed or a range has no end yet. setValue() emits an error event with the code invalid-date when the value does not fit the mode, and it does not emit confirm.
type DateValue = {value: string; // ISO YYYY-MM-DDdate: Date; // local midnightformatted: string; // the text as the input shows it};
Single date
#Date range
#calendar.range.minLength and calendar.range.maxLength bound a range in days, both ends included. The demo accepts 2 to 14 days.
Multiple dates
#calendar.multiple.max bounds the number of dates. Clicking a selected day removes it. behavior.closeOnSelect is not used in this mode.
Limits
#calendar.range.minLengthandcalendar.range.maxLengthfor ranges.calendar.multiple.maxfor multiple dates.calendar.minDate,maxDate,disabledDates,enabledDates,disabledWeekdaysandisDateDisableddecide which days can be selected. See Disabled Dates.
Forms
#When the input has a name, the picker moves the name to a hidden input placed after it, so a form submits ISO values instead of the displayed text. The hidden input is removed and the name restored on destroy().
<form><input id="date" name="birthday" /><button type="submit">Send</button></form>
| Mode | Hidden value |
|---|---|
| single | 2025-03-14 |
| range | 2025-03-14/2025-03-20 |
| multiple | 2025-03-14,2025-03-16 |
An incomplete range gives an empty string. The visible input gets input and change events when a value is committed, and a form reset restores the initial value. With ui.endInput, each field with a name gets its own hidden ISO input.
Initial value
#On create(), the picker reads the existing input text, either in the serialized form above or in the display format.