Skip to content

onSelect

Hears a stretch of time a person selected, in a selectable calendar.

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

It receives { start, end, allDay, resourceId? } when a person finishes a selection: a drag across empty time, a tap on a touch screen (or a handle pulled), or Shift+arrows then Enter on the keyboard. Timed: ZonedDateTimes in the calendar’s zone. All-day: dates, the end being the day after the last. skipped: true says a moment fell in a clock change’s gap and was moved on.

The selection stays drawn: open your form, then clear it with calendar.select(null) (or let a click elsewhere do it, onUnselect). A selection shown by your code (calendar.select(…)) is not said here.

import { createCalendar } from '@dzcalendar/dom';
const calendar = createCalendar(element, {
timeZone: 'Europe/Paris',
selectable: true,
onSelect: (selection) => {
if (confirm(`Block ${selection.start.toString()} → ${selection.end.toString()}?`)) console.log('blocked');
calendar.select(null);
},
});

In the frameworks it is an output: Angular’s (selected), React’s onSelect, Vue’s @selected. The frameworks’ two-way selection follows it too (Angular [(selection)], React selection and onSelectionChange, Vue v-model:selection).