Skip to main content

Event handling

Attach event listeners​

Use the calendar.events.on() method to attach event listeners:

calendar.events.on("change",function(date, oldDate, byClick){
console.log("Change selection from "+oldDate+" to "+date);
console.log(click);
});

For example, you can attach Calendar to an input that displays the selected date:

<input type="text" id="date" />
const calendar = new dhx.Calendar("calendar_container");
calendar.events.on("change",(date)=>{
document.getElementById("date").value = date.getFullYear() +
"-" + (date.getMonth() + 1) + "-" +date.getDate();
});

You can attach several handlers to one event. Calendar executes all handlers.

note

Event names are case-insensitive.

Related sample: Calendar. Events

Detach event listeners​

The calendar.events.detach() method removes an event listener:

calendar.events.on("change",function(date, oldDate, byClick){
console.log("Change selection from "+oldDate+" to "+date);
console.log(click);
});
calendar.events.detach("change");

Trigger events​

Call calendar.events.fire() to trigger an event manually:

calendar.events.fire("name",args);
// where args is an array of arguments

Event list​

For the full event list, see the Calendar API.