This page uses a custom rule for event creating (maximum of 3 days can be selected),
implemented using the
onTimeRangeSelecting event. Read more about the
time range selecting.
Agent-readable demo data
- Title
- Time Range Selecting (JavaScript Scheduler) | DayPilot Pro for JavaScript Demo
- Tree
- DayPilot JavaScript Demo
- Catalog root
- Default
- Description
- This page uses a custom rule for event creating (maximum of 3 days can be selected),
implemented using the onTimeRangeSelecting event. Read more about the time range selecting.
Inline demo script 1
const dp = new DayPilot.Scheduler("dp", {
startDate: "2026-01-01",
days: 365,
scale: "Day",
timeHeaders: [
{groupBy: "Month", format: "MMMM yyyy"},
{groupBy: "Cell", format: "d"}
],
treeEnabled: true,
resources: [
{name: "Room A", id: "A"},
{name: "Room B", id: "B"},
{name: "Room C", id: "C"},
{name: "Room D", id: "D"},
{name: "Room E", id: "E"},
{name: "Room F", id: "F"},
{name: "Room G", id: "G"},
{name: "Room H", id: "H"},
{name: "Room I", id: "I"},
{name: "Room J", id: "J"},
{name: "Room K", id: "K"}
],
eventEndSpec: "Date",
onTimeRangeSelected: async args => {
const modal = await DayPilot.Modal.prompt("New event name:", "Event");
const name = modal.result;
dp.clearSelection();
if (!name) return;
const e = new DayPilot.Event({
start: args.start,
end: args.end,
id: DayPilot.guid(),
resource: args.resource,
text: name
});
dp.events.add(e);
dp.message("Created");
},
onTimeRangeSelecting: args => {
if (args.duration.totalDays() > 3) {
args.allowed = false;
args.left.enabled = false;
args.right.enabled = true;
args.right.html = "Maximum selection size is 3 days.";
}
},
height: 350
});
dp.init();
dp.scrollTo("2026-03-25");