`} />
You do not need the library's own stylesheet. Tabler styles the calendar in `tabler.css`.
Vanilla Calendar Pro 3.4 splits several months, the time picker, week numbers, popups and animation into extensions. Tabler registers every extension the loaded library exports, so options such as `data-bs-display-months-count="2"` work without importing them yourself.
## Usage
### Basic input
Use `type="text"`, not `type="date"`, so the browser's own picker does not open too. Add `autocomplete="off"` so the browser does not cover the calendar with old values.
### Icon input
Wrap the field in `.input-icon` and add a calendar icon, so users can see what the field is for at a glance. The popup lines up with the wrapper, not with the input inside it.
### Initial value
A `value` in `YYYY-MM-DD` format is shown on load and the calendar opens on that month. You can also preselect dates with `data-bs-selected-dates`, which takes a JSON array.
### Min and max dates
Limit the pickable dates with `data-bs-date-min` and `data-bs-date-max`. Dates outside the range are shown but cannot be picked.
### Date range
Set `data-bs-selection-mode="multiple-ranged"` to pick a start and an end date. The calendar closes after the second date. The field shows both dates with a dash between them.
### Multiple dates
Set `data-bs-selection-mode="multiple"` to pick any number of dates. The calendar stays open until focus leaves it. The field lists the dates with commas.
### Two months
Add `data-bs-display-months-count="2"` to show two months side by side. This helps with ranges that cross a month boundary.
### First day of the week
The week starts on Monday. Set `data-bs-first-weekday="0"` to start it on Sunday.
### Week numbers
Add `data-bs-week-numbers="true"` to show the week number in front of each row. Use it where people plan by week, for example delivery dates or sprints.
### Placement
The popup lines up with the left edge of the field. Set `data-bs-placement` to `center`, `right` or `auto` to change that.
### Date format
The field shows the date in the format of `data-bs-locale`. Set `data-bs-date-format` to a pattern to write it the same way in every language. The pattern uses `YYYY` for the year, `MM` and `M` for the month, and `DD` and `D` for the day. The short tokens drop the leading zero. Everything else is copied as it is. Use `iso` as a shortcut for `YYYY-MM-DD`.
A field with a pattern also reads its `value` in that pattern, so a form the server sends back keeps the picked date selected.
### Button trigger
Any element can open the calendar, not only an input. A button shows the picked date as its text. Put the text in a child with `data-bs-datepicker-display` so an icon next to it stays.
To show the date somewhere else, pass the `displayElement` option when you create the picker in JavaScript.
### Inline calendar
Add `data-bs-inline="true"` to render the calendar in place instead of a popup. Tabler creates inline calendars on page load, so they need no extra JavaScript. An inline calendar has no background or border of its own. Put it in a card to give it a surface.
Inline calendars take the same options as popups:
To submit the picked dates with a form, put a hidden input inside the calendar. Tabler writes the dates to it in `YYYY-MM-DD` format, separated by commas.
A popup field works the same way. Point `data-bs-bound-input` at a hidden input and give the `name` to that input, not to the field. The field shows the date in the visitor's language, and the form sends `YYYY-MM-DD`. When the hidden input already has a value, the picker selects that date on page load.
## JavaScript
### Via data attributes
Add `data-bs-toggle="datepicker"` and Tabler does the rest. Inputs open on focus, other elements open on click, and inline calendars and fields with a value, `data-bs-selected-dates` or `data-bs-bound-input` render on page load. Every option below can be set as a `data-bs-*` attribute, for example `data-bs-selection-mode="multiple"`.
### Via JavaScript
Create the picker yourself when you need options that do not fit in an attribute, such as a date format or a callback:
```js
const datepicker = new tabler.Datepicker(document.getElementById('my-date'), {
selectionMode: 'multiple-ranged',
firstWeekday: 0,
dateFormat: { month: 'short', day: 'numeric', year: 'numeric' },
});
```
### Options
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `dateMin` | string, number, Date | `null` | First pickable date, as `YYYY-MM-DD`. |
| `dateMax` | string, number, Date | `null` | Last pickable date, as `YYYY-MM-DD`. |
| `boundInput` | string, element | `null` | Input that gets the picked dates as `YYYY-MM-DD`, separated by commas. An inline calendar uses a hidden input inside it. |
| `dateFormat` | string, object, function | `null` | How the date is shown in the field. Pass a pattern such as `'DD.MM.YYYY'`, `'iso'`, `Intl.DateTimeFormat` options or a `function(date, locale)` that returns a string. |
| `displayElement` | string, element, boolean | `null` | Element that shows the picked date. A button uses itself or its `[data-bs-datepicker-display]` child. Set `false` to show nothing. |
| `displayMonthsCount` | number | `1` | Months shown side by side. |
| `firstWeekday` | number | `1` | First day of the week: 0 is Sunday, 1 is Monday. |
| `inline` | boolean | `false` | Render the calendar in place instead of a popup. |
| `locale` | string | `'default'` | Locale for month names and the date shown in the field, for example `'en-US'` or `'de-DE'`. A `dateFormat` pattern takes over the field. |
| `positionElement` | string, element | `null` | Element the popup lines up with. Defaults to the `.input-icon` or `.input-group` wrapper, or the field itself. |
| `selectedDates` | array | `[]` | Preselected dates as `YYYY-MM-DD`. |
| `selectionMode` | string | `'single'` | `'single'`, `'multiple'` or `'multiple-ranged'`. |
| `placement` | string | `'left'` | Where the popup lines up with the field: `'left'`, `'center'`, `'right'` or `'auto'`. |
| `weekNumbers` | boolean | `false` | Show the week number in front of each row. |
| `datepickerTheme` | string | `null` | Force the popup's theme to `'light'`, `'dark'` or `'auto'`. By default it follows the nearest `[data-bs-theme]`. |
| `vcpOptions` | object | `{}` | Any [Vanilla Calendar Pro option](https://vanilla-calendar.pro/docs/reference/settings), passed straight through. |
Use `vcpOptions` for everything the plugin can do that Tabler does not expose, for example disabling weekends or adding a time picker:
```js
const datepicker = new tabler.Datepicker(element, {
vcpOptions: {
disableDatesPast: true,
disableWeekdays: [0, 6],
selectionTimeMode: 24,
},
});
```
### Methods
| Method | Description |
| --- | --- |
| `show()` | Opens the popup. Does nothing for an inline calendar. |
| `hide()` | Closes the popup. |
| `toggle()` | Opens or closes the popup. |
| `getSelectedDates()` | Returns the picked dates as an array of `YYYY-MM-DD` strings. |
| `setSelectedDates(dates)` | Sets the picked dates. Takes an array of `YYYY-MM-DD` strings. |
| `dispose()` | Removes the calendar and the instance. |
| `calendar` | The Vanilla Calendar Pro instance, for anything the methods above do not cover. |
| `Datepicker.getInstance(element)` | Returns the instance for an element, or `null`. |
| `Datepicker.getOrCreateInstance(element)` | Returns the instance, or creates one. |
### Events
| Event | Description |
| --- | --- |
| `show.bs.datepicker` | Fires before the popup opens. Call `preventDefault()` to keep it closed. |
| `shown.bs.datepicker` | Fires once the popup is open. |
| `hide.bs.datepicker` | Fires before the popup closes. Call `preventDefault()` to keep it open. |
| `hidden.bs.datepicker` | Fires once the popup is closed. |
| `change.bs.datepicker` | Fires when the user picks a date. The event has `dates`, an array of `YYYY-MM-DD` strings, and `event`, the click. |
```js
document.getElementById('my-date').addEventListener('change.bs.datepicker', (event) => {
console.log(event.dates);
});
```
## Accessibility
- Always add a `