Skip to content

onCreateRequest

Hears “New event here” chosen in the context menu: the application opens its own editor.

Type(request: CreateRequest) => void
Defaultnot set
Live update (update())Yes
Declared inpackages/dom/src/calendar.ts

With it, the context menu on empty time offers “New event at 14:30” (on a day: “New all-day event on …”); chosen, the calendar creates nothing and gives you { allDay, start, resourceId? }:

  • in a time grid, allDay: false and start an Instant, snapped to snapMinutes — on a repeated hour, two entries, one per reading, so the moment is never a guess;
  • on a day, allDay: true and start a date.

Open your editor there, then create the event with calendar.run({ type: 'event.create', event }) or your server. Without onCreateRequest, the menu has no such entry.

import { createCalendar } from '@dzcalendar/dom';
const calendar = createCalendar(element, {
timeZone: 'Europe/Paris',
editable: true,
onCreateRequest: (request) => {
const title = prompt('Title?');
if (!title) return;
const start = request.allDay ? request.start.toString() : request.start.toZonedDateTimeISO('Europe/Paris').toString();
calendar.run({ type: 'event.create', event: { title, start, ...(request.allDay ? { allDay: true } : { duration: { minutes: 30 } }) } });
},
});

In the frameworks it is an output: Angular’s (createRequest), React’s onCreateRequest, Vue’s @create-request.