API
Air Datepicker has a convenient API that gives even more control over the component. The methods are accessed via a reference to the calendar instance:
let dp = new AirDatepicker('#el');
dp.show();
Methods
Shows calendar.
Hides calendar.
Goes to the next month/year/decade.
Goes to the prev month/hear/decade.
Selects one or several dates if array is passed
Date | string | number
Date
format, or a string in ISO format, or a time in milliseconds. If a string or number cannot be converted to a date, this value will be ignored.boolean
true
, the time from the passed date will be set to the value of the timepicker. By default, false
- when selecting a date, the current time is set.
Unselected passed date
Date | string | number
Clears all selected dates.
Formats date in passed format.
Date | string | number
string
dateFormat
option. You could see available tokens in documentation section
Destroys calendar instance. Remove itself from DOM tree and all events from target element.
Updates calendar options. Using this method, you can set new values for the minimum or maximum dates, change the calendar language, etc.
object
boolean
true
then onSelect and onChangeView callbacks won't be triggered
Sets the new value of the calendar view.
"days" | "months" | "years"
boolean
true
, then onChangeView won't be triggered
Sets a new date for displaying the calendar. It is used when, for example, you need to show some other month without having to select a date.
Date | string | number
Sets the focus to the cell with the passed date.
Date | string | number
boolean
true
and the new date is outside the current view date, the new view date will be set.
Switch to the next view type. The view options are in order from days -> months -> years.
Date | string | number
Switching to the previous view type.
Date | string | number
(days|months|years) => Date[]
Returns all dates that should be currently displayed in calendar.
((date: Date|string|number|Array<Date|string|number>)) => void
Disables one or multiple dates.
((date: Date|string|number|Array<Date|string|number>)) => void
Enables dates previously disabled.
Properties
HTMLDivElement
DOM element of the calendar.
HTMLInputElement
DOM element on which calendar was initialized. Type of the element depends on generic value, which can be passed with initialization. By default it is HTMLInputElement.
Date
Current view date.
"days" | "months" | "years"
Current view of the calendar.
Date[]
An array of selected dates.
Date | false
A focused date.
boolean
Is calendar visible.
Set<string>
Set of disabled dates
boolean
If true
then calendar has been destroyed with destroy() method