onTimeRangeSelecting event handler is used to customize time range selecting.
Agent-readable demo data
- Title
- Time Range Selecting (JavaScript Event Calendar) | DayPilot Pro for JavaScript Demo
- Tree
- DayPilot JavaScript Demo
- Catalog root
- Default
- Description
- onTimeRangeSelecting event handler is used to customize time range selecting.
Inline demo script 1
const dp = new DayPilot.Calendar("dp", {
startDate: DayPilot.Date.today(),
viewType: "Week",
eventDeleteHandling: "Update",
onTimeRangeSelected: async args => {
const modal = await DayPilot.Modal.prompt("New event name:", "Event");
dp.clearSelection();
if (modal.canceled) {
return;
}
dp.events.add({
start: args.start,
end: args.end,
id: DayPilot.guid(),
resource: args.resource,
text: modal.result
});
dp.message("Created");
},
timeRangeSelectingStartEndEnabled: true,
timeRangeSelectingStartEndFormat: "h:mm tt",
onTimeRangeSelecting: args => {
// args.html = args.duration.toString("h:mm") + " hours";
if (args.duration > DayPilot.Duration.hours(2)) {
args.allowed = false;
args.top.enabled = true;
args.top.html = "Maximum 2 hours allowed.";
args.bottom.enabled = false;
}
}
});
dp.init();
const app = {
init() {
this.loadEventData();
},
loadEventData() {
const events = [
{
start: DayPilot.Date.today().firstDayOfWeek().addDays(1).addHours(12),
end: DayPilot.Date.today().firstDayOfWeek().addDays(1).addHours(15),
id: DayPilot.guid(),
text: "Event 1"
},
{
start: DayPilot.Date.today().firstDayOfWeek().addDays(1).addHours(16),
end: DayPilot.Date.today().firstDayOfWeek().addDays(1).addHours(18),
id: DayPilot.guid(),
text: "Event 2"
},
];
dp.update({events});
}
};
app.init();