Skip to content

rules

What a person’s moves, resizes and drops are checked against before they happen.

TypeOmit<RulesContext, 'displayZone' | 'businessHours'>
Defaultnot set
Live update (update())Yes
Declared inpackages/core/src/kernel.ts
  • constraint: where events may go — 'businessHours' (inside businessHours; nothing without them), { groupId } (inside that group’s events: a shift the appointments must stay in), or { spans: [{ s, e }] } (inside stretches given in epoch milliseconds).
  • overlap: false — no event over another (background events aside); a function (still, moving) => boolean decides pair by pair, true meaning they may overlap.
  • allow: (placement) => boolean, your last word on where an event would go (placement.event, start, end, resourceIds, external for one coming from outside). A timed event’s start and end are in its own zone.
  • validRange: { start?, end? } (PlainDates, the end exclusive): an event cannot be moved, resized or dropped onto days outside (navigation is not limited).

A gesture the rules refuse is not made — the event goes back — and onProposalRefused hears why. A command your code runs is checked too when asked: calendar.run(command, { validate: true }). A resource’s own eventConstraint and eventOverlap win over these for its events.

import { Temporal } from '@dzcalendar/core';
import { createCalendar } from '@dzcalendar/dom';
const calendar = createCalendar(element, {
timeZone: 'Europe/Paris',
editable: true,
businessHours: { daysOfWeek: [1, 2, 3, 4, 5], start: '08:30', end: '18:00' },
rules: {
constraint: 'businessHours',
overlap: false,
// Nothing on a Friday afternoon.
allow: ({ start }) => !(start instanceof Temporal.ZonedDateTime && start.dayOfWeek === 5 && start.hour >= 14),
},
onProposalRefused: (proposal) => console.log('refused', proposal),
});
// Later: overlaps allowed again.
calendar.update({ rules: { constraint: 'businessHours' } });

In Angular and Vue it goes in options; in React it is a prop.

Drag an event outside the hours, or onto another: it goes back.