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:
| Situation | Message |
|---|---|
| Text that is not a date | labels.invalidDate |
| A typed date that is disabled | labels.unavailableDate |
| A typed date before minDate | labels.beforeMinDate |
| A typed date after maxDate | labels.afterMaxDate |
| A range the limits refuse | labels.invalidRange |
Format
#ui.format is "auto" or a pattern of three parts with one separator.
| Part | Meaning |
|---|---|
| d, dd | Day, without or with a leading zero. |
| M, MM | Month, without or with a leading zero. |
| yy, yyyy | Year 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.
Parsing
#- Separators
/,.,-and spaces are accepted when typing. - A compact eight-digit form such as
14032025and 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.
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
minDate or after maxDate use the messages labels.beforeMinDate and labels.afterMaxDate, with {date} replaced by the limit in the display format.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();