Skip to content

onEventChange

Hears every change a person makes — a drag, a resize, the keyboard, the menu, the editor, an undo — to persist it.

Type(change: EventChange) => void
Defaultnot set
Live update (update())Yes
Declared inpackages/dom/src/settings.ts

It receives one change at a time:

  • cause: 'command' (a person’s change), 'undo' or 'redo' — persist each, an undo is a change too;
  • command: what was asked (absent for an undo or a redo);
  • before and after: the first event touched as it was and as it is now (before null when created, after null when deleted), its data in props; changes: every event and series it touched;
  • revert(): takes back exactly this change — your server refused it — even if others came after. It returns false, doing nothing, when the events changed again since, or for one step of a merged gesture or a transaction.

calendar.undo(), calendar.redo() and calendar.run(cmd, { validate: true }) are said here too; your own calendar.run() without validate and a source’s deliveries are not — a source with save writes its own changes back.

import { createCalendar } from '@dzcalendar/dom';
createCalendar(element, {
timeZone: 'Europe/Paris',
editable: true,
onEventChange: async (change) => {
const ev = change.after ?? change.before;
const res = await fetch(`/api/events/${ev?.id}`, {
method: change.after ? 'PUT' : 'DELETE',
body: change.after ? JSON.stringify({ start: change.after.start.toString(), end: change.after.end.toString() }) : null,
});
// Refused by the server: exactly this change taken back.
if (!res.ok) change.revert();
},
});

In the frameworks it is an output: Angular’s (eventChange), React’s onEventChange, Vue’s @event-change.