rules
What a person’s moves, resizes and drops are checked against before they happen.
| Type | Omit<RulesContext, 'displayZone' | 'businessHours'> |
|---|---|
| Default | not set |
Live update (update()) | Yes |
| Declared in | packages/core/src/kernel.ts |
What it does
Section titled “What it does”constraint: where events may go —'businessHours'(insidebusinessHours; 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) => booleandecides pair by pair,truemeaning they may overlap.allow:(placement) => boolean, your last word on where an event would go (placement.event,start,end,resourceIds,externalfor one coming from outside). A timed event’sstartandendare 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.
Example
Section titled “Example”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' } });import { Component } from '@angular/core';import { DZ_CALENDAR } from '@dzcalendar/angular';
@Component({ selector: 'app-agenda', imports: [DZ_CALENDAR], template: `<dz-calendar timeZone="Europe/Paris" [editable]="true" [businessHours]="true" [options]="{ rules: { constraint: 'businessHours', overlap: false } }" />`,})export class Agenda {}import { DzCalendar } from '@dzcalendar/react';
export function Agenda() { return <DzCalendar timeZone="Europe/Paris" editable businessHours rules={{ constraint: 'businessHours', overlap: false }} />;}<script setup lang="ts">import { DzCalendar } from '@dzcalendar/vue';</script>
<template> <DzCalendar time-zone="Europe/Paris" editable business-hours :options="{ rules: { constraint: 'businessHours', overlap: false } }" /></template>In Angular and Vue it goes in options; in React it is a prop.
Live demo
Section titled “Live demo”Drag an event outside the hours, or onto another: it goes back.
See also
Section titled “See also”businessHours— the hours'businessHours'means.editable— what a person may change.resources— a resource’s own rules.