timepicker-ui
4.6.0GitHub
timepicker-ui
Guides / Typed Input

Typed Date Input, Format and Mask

Users can type into the input of @pglejzer/datepicker-ui, the companion of timepicker-ui. ui.format sets the text pattern, ui.mask formats digits while typing.

Typed input

#

The user can type into the input. Text is parsed on blur and on Enter. A valid date updates the value and reformats the text. An empty input clears the value. Anything else sets aria-invalid and a custom validity message on the input, adds the class dp-ui--error to the host and emits error. The message comes from a label:

SituationMessage
Text that is not a datelabels.invalidDate
A typed date that is disabledlabels.unavailableDate
A typed date before minDatelabels.beforeMinDate
A typed date after maxDatelabels.afterMaxDate
A range the limits refuselabels.invalidRange

Format

#

ui.format is "auto" or a pattern of three parts with one separator.

Pattern parts, each used once and in any order
PartMeaning
d, ddDay, without or with a leading zero.
M, MMMonth, without or with a leading zero.
yy, yyyyYear with two or four digits.

The separator is one of /, ., - or a space, used between all parts. With "auto", the order and separator come from Intl for calendar.locale, with two-digit day and month and a four-digit year. Any other string emits invalid-option and "auto" is used.

Mask

#

ui.mask formats digits as the user types, in single mode and in the two range fields, at day precision only. Typing 14032025 gives 14.03.2025 with the pattern below. A separator typed after one digit pads the group with a zero.

Format and mask
import DatepickerUI from "@pglejzer/datepicker-ui";
import "@pglejzer/datepicker-ui/index.css";
new DatepickerUI("#date", {
ui: { format: "dd.MM.yyyy", mask: true },
}).create();

Parsing

#
  • Separators /, ., - and spaces are accepted when typing.
  • A compact eight-digit form such as 14032025 and non-Latin digits are accepted.
  • A two-digit year means 20xx up to 20 years ahead of the current year, and 19xx after that.
  • In range mode the input holds two dates separated by an en dash, for example 14.03.2025 – 20.03.2025. A hyphen with spaces around it is also accepted when typing.
  • In multiple mode dates are separated by commas.

Validation

#

calendar.validate checks the committed value with your own rule. It receives the value as getValue() returns it, or null when the field is empty. Return a message to mark the field invalid, or undefined or null when it is fine.

Weekdays only
import DatepickerUI from "@pglejzer/datepicker-ui";
import "@pglejzer/datepicker-ui/index.css";
new DatepickerUI("#date", {
calendar: {
validate: (value) => {
if (!value || !("date" in value)) return null;
return value.date.getDay() % 6 === 0 ? "Weekdays only" : null;
},
},
}).create();

It never blocks a pick or a commit. A message sets aria-invalid and a custom validity message on the input, adds dp-ui--error to the host and emits error with the code invalid-value. It runs after setValue(), typed input and a commit. A throw is rethrown asynchronously and counts as valid.

Typed dates outside the limits

Typed dates before minDate or after maxDate use the messages labels.beforeMinDate and labels.afterMaxDate, with {date} replaced by the limit in the display format.
index.ts
new DatepickerUI("#date", {
calendar: { minDate: "2026-01-01", maxDate: "2026-12-31" },
labels: {
beforeMinDate: "Pick a date on or after {date}",
afterMaxDate: "Pick a date on or before {date}",
},
}).create();
#
Esc