Skip to content

onSlotClick

Hears a bookable slot (availableSlots) clicked — or Enter on it.

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

It receives the slot exactly as you gave it — its start, end and any field of yours (resourceId, seats from @dzcalendar/pro/slots, an id). The calendar creates nothing: book it, and have your server check it again (checkSlot from @dzcalendar/slots) before saving, since someone else may have taken it. Without onSlotClick, slots are only shown, not clickable.

import { createCalendar } from '@dzcalendar/dom';
const calendar = createCalendar(element, {
timeZone: 'Europe/Paris',
availableSlots: [],
onSlotClick: async (slot) => {
const res = await fetch('/api/bookings', { method: 'POST', body: JSON.stringify({ start: slot.start.toString() }) });
if (!res.ok) alert('Just taken, sorry.');
calendar.refetch();
},
});

In the frameworks it is an output: Angular’s (slotClick), React’s onSlotClick, Vue’s @slot-click.