Display calendar and pick dates (singular or range).
HTML
<div class="calendar"></div>JS
const options = {
date: '2019-12-21'
}
const my_calendar = new TavoCalendar('.calendar', options);Available options:
format(optional) -- defaults toYYYY-MM-DDlocale(optional) -- display of weekday names, month (defaultsen)date(optional) -- calendar focus date (defaults to absolute date),date_start(optional) -- range end date (defaults tonull),date_end(optional) -- range start date (defaults tonull),selected(optional) -- mark dates selected (defaults to[])highlight(optional) -- special dates (defaults to[])blacklist(optional) -- disable dates (defaults to[])range_select(optional) -- range select mode (defaults tofalse)multi_select(optional) -- mltiple date mode (defaults tofalse)future_select(optional) -- disable selecting days afterdate(defaults totrue)past_select(optional) -- disable selecting days beforedate(defaults tofalse)frozen(optional) -- disable all interactions (defaults tofalse)highligh_sunday(optional) -- highlight sundays (defaults totrue)
Selecting
getSelected()-- returns an array of selected dates (in multiselect mode) or singleaddSelected(date)-- add date to selectedclearSelected()-- clear all selected datesgetStartDate()-- range startsetStartDate(date)-- set range startgetEndDate()-- range endsetEndDate(date)-- set range endgetRange()- range object { start: '2012-12-10', end: '2012-12-15'}clearRange()- clear rangesetRange(date1, date2)- set full rangeclear()- clear all selections
Moving calendar window
getFocusYear()-- calendar focus yearsetFocusYear(year)-- set calendar focus yeargetFocusMonth()-- calendar focus monthsetFocusMonth(month)-- set calendar focus monthnextMonth()-- move to next monthprevMonth()-- move to prev month
Other
sync(other_calendar)-- sync two or more calendarscalendarA.sync(calendarB)
Events
calendar-change-- fired when month changescalendar-range-- fired on day changecalendar-select-- fired on day changecalendar-reset-- fired on range reset
Select range from future date.
const options = {
range_select: true
}
const calendar_el = document.querySelector('.calendar');
const my_calendar = new TavoCalendar(calendar_el, options)
calendar_el.addEventListener('calendar-range', (ev) => {
const range = my_calendar.getRange();
console.log('Start', range.start)
console.log('End', range.end)
});