Date picker guides
Handle date-only values, native forms, availability, server rendering and common setup issues.
Date values
A DateValue represents a calendar day as
{ day, month, year }. The month is from 1 to 12 and the year is from 0001
to 9999. It has no time or time zone, so it will not shift when your app changes time
zones.
Use an ISO YYYY-MM-DD string at form or API boundaries. The DOM picker
returns DateValue from getValue() by default.
getISOValue() returns the selected single date as
YYYY-MM-DD. Use valueAs: "date" when an API needs a native
Date. That date uses local calendar fields at noon. Keep ISO strings and
native dates at the boundary instead of parsing a date-only string with
new Date("YYYY-MM-DD") or serializing it with toISOString().
import {
fromLocalDate,
toIsoDate,
toLocalDate,
type DateValue,
} from "@litopis/core";
const value: DateValue = { day: 2, month: 4, year: 2026 };
const iso = toIsoDate(value); // "2026-04-02"
const localDate = toLocalDate(value); // local date at noon
const sameDay = fromLocalDate(localDate);
The format option changes visible input text. Form values remain ISO.
Supported formats are yyyy-mm-dd, dd.mm.yyyy,
dd/mm/yyyy and mm/dd/yyyy. See the
input format example.
locale is a BCP 47 tag used by Intl for month names, weekday
labels and accessibility text. When omitted it uses the browser language. Outside a
browser the default locale is en-US. An invalid or unsupported locale
also uses en-US. Week start follows locale data when available and region
data otherwise. Set firstDayOfWeek to override it. The calendar uses the
proleptic Gregorian calendar and does not model historical Julian/Gregorian cutovers.
See the locale example.
Set messages to override individual labels while keeping the locale
defaults for the rest. See the API reference for message
keys.
For a full picker setup see the basic example. For date limits see date bounds. For month and year selection see the month and year example.
Native forms and validation
Put the picker root inside its form and set name in the picker options.
Litopis adds hidden controls with ISO values for FormData. The visible
text input does not need a name attribute. Add required to a
supplied input slot for the browser's empty-field check. Validate your business rules
in the submit handler or on the server.
<form id="booking-form">
<div id="booking-date">
<input slot="input" required />
</div>
<button type="submit">Check date</button>
<output id="booking-result" aria-live="polite"></output>
</form>
import { createDatePicker } from "@litopis/dom";
import "@litopis/dom/styles/base.css";
const form = document.querySelector<HTMLFormElement>("#booking-form");
const root = document.querySelector<HTMLElement>("#booking-date");
const result = document.querySelector<HTMLOutputElement>("#booking-result");
if (!form || !root || !result) throw new Error("Booking form markup is missing.");
createDatePicker(root, {
label: "Appointment date",
name: "appointmentDate",
});
form.addEventListener("submit", (event) => {
event.preventDefault();
const value = new FormData(form).get("appointmentDate") as string | null;
result.textContent = value || "No date selected.";
});
A range can use name: { start: "checkIn", end: "checkOut" }. Require both
visible inputs and check that the range is complete before saving. See the
form example and
range example.
Load availability
disabledDates takes the complete list of unavailable
DateValue objects for your data. It does not take the dates that are
available. This setup keeps the list you already have in memory:
<div id="static-availability"></div>
import type { DateValue } from "@litopis/core";
import { createDatePicker } from "@litopis/dom";
import "@litopis/dom/styles/base.css";
const root = document.querySelector<HTMLElement>("#static-availability");
if (!root) throw new Error("Availability picker root is missing.");
const unavailableDates: readonly DateValue[] = [
{ day: 4, month: 4, year: 2026 },
{ day: 9, month: 4, year: 2026 },
];
createDatePicker(root, {
label: "Booking date",
disabledDates: unavailableDates,
});
For remote availability, fetch the disabled dates for the visible month. The callback
does not run on initial render, so load the starting month yourself. The request
counter below ignores older responses. Keep the full options object because
setOptions() replaces the current options.
<div id="remote-availability"></div>
<p id="availability-status" role="status"></p>
import { getToday, startOfMonth, type DateValue } from "@litopis/core";
import { createDatePicker, type DatePickerOptions } from "@litopis/dom";
import "@litopis/dom/styles/base.css";
const root = document.querySelector<HTMLElement>("#remote-availability");
const status = document.querySelector<HTMLElement>("#availability-status");
if (!root || !status) throw new Error("Availability picker markup is missing.");
const today = getToday();
let latestRequest = 0;
let options: DatePickerOptions = {
label: "Booking date",
today,
disabledDates: [],
onVisibleMonthChange: (month) => {
void loadAvailability(month);
},
};
const picker = createDatePicker(root, options);
async function loadAvailability(month: DateValue): Promise<void> {
const request = ++latestRequest;
status.textContent = "Loading availability...";
const query = new URLSearchParams({
year: String(month.year),
month: String(month.month),
});
try {
const response = await fetch(`/api/availability?${query}`);
if (!response.ok) throw new Error("Availability request failed.");
const disabledDates = (await response.json()) as DateValue[];
if (request !== latestRequest) return;
options = { ...options, disabledDates };
picker.setOptions(options);
status.textContent = "";
} catch {
if (request !== latestRequest) return;
status.textContent = "Could not load availability.";
}
}
void loadAvailability(startOfMonth(today));
The endpoint in this example returns a JSON array of unavailable
DateValue objects for the requested month. Month numbers are from 1 to
12. While a request is pending or has failed, block booking in your app and verify
availability again on the server before saving. See the
disabled dates example.
Mounting and server rendering
createDatePicker() creates DOM elements. Call it after the picker root
exists in the browser and call destroy() when that view is removed. The
React, Vue, Solid, Svelte and Web Components guides show their mount and cleanup
patterns.
import { createCalendarState } from "@litopis/core";
export function getServerCalendar() {
return createCalendarState({ locale: "en-GB" }).grid;
}
Use @litopis/core to build date state or a grid on the server. Mount the
DOM picker on the client. See the
headless core example and the
React,
Vue,
Solid,
Svelte and
Web Components guides.
Troubleshooting
-
No styles: import
@litopis/dom/styles/base.cssor the theme adapter your app uses. See Styling. -
Empty
FormData: put the picker inside a form and set itsnameoption. A range needs both endpoints before it has a complete value. -
Invalid value: pass a valid
DateValueobject with a month from 1 to 12. Use an ISO string for form or API data, not asselected. - Popover or keyboard issue: check the popover example and keyboard guidance. Keep the visible input focusable.