CalendarDrag
Feature
This feature provides drag-based event creation and modification for Calendars. When enabled (which is the default for calendars), the user can do the following via the mouse or touch screen:
- Create events by touching (or pressing the mouse button in) an the empty space and dragging. As the drag progresses, a tentative event is rendered. On release, the EventEdit feature displays the event edit dialog to complete the process. This can be disabled via the creatable config.
- Adjust the start or end times of an event in the day or week views by dragging the top or bottom of an event. This can be disabled via the resizable config or the resizable field on a per-event basis.
- Adjust the start or end date of an all-day event in the month view by dragging the left-most or right-most end of an event. This can be disabled via the resizable config or the resizable field on a per-event basis.
- Move an event from its current time (in day or week views) or date (in all views except agenda) by dragging the body of an event. This can be disabled via the draggable config or via the draggable field on a per-event basis.
// change name for events created by drag to "Event":
let calendar = new Calendar({
features : {
drag : {
newName : 'Event'
}
}
});
Asynchronous validation of resize, move and create operations
You can easily add a confirmation step after an operation to show a dialog to the end user. This is done using the beforeDragMoveEnd, beforeDragCreateEnd and beforeDragResizeEnd events.
let calendar = new Calendar({
listeners : {
// Async event listeners allowing you to veto drag operations
beforeDragMoveEnd : async({ eventRecord }) => {
const result = await MessageDialog.confirm({
title : 'Please confirm',
message : 'Is this the start time you wanted?'
});
// Return true to accept the drop or false to reject it
return result === MessageDialog.yesButton;
},
beforeDragResizeEnd : async({ eventRecord }) => {
const result = await MessageDialog.confirm({
title : 'Please confirm',
message : 'Is this the duration you wanted?'
});
// Return true to accept the drop or false to reject it
return result === MessageDialog.yesButton;
},
beforeDragCreateEnd : async({ eventRecord }) => {
const result = await MessageDialog.confirm({
title : 'Please confirm',
message : 'Want to create this event?'
});
// Return true to accept the drop or false to reject it
return result === MessageDialog.yesButton;
}
}
});
Converting "All day" events to intra day events
You may drag an "All day" event out of the top row of a DayView and into the body of the view.
The event's duration will be preserved if possible.
If the newly calculated end time (based on the dropped-at time and the duration of the event) will overflow the end of that date then the event is converted to the duration configured in the DayView's autoCreate.
This feature is enabled by default.
The example below demonstrates validation of drag gestures so that no event intersects with any TimeRange which have its disabled field set.
Useful configs
| Config | Description |
|---|---|
| creatable | Allow drag-creating new events |
| draggable | Allow dragging events to new times |
| resizable | Allow drag-resizing event edges |
| tooltip | Tooltip shown during drag operations |
| validateCreateFn | Custom validation for drag-create |
See also
- Calendar — The Calendar that this feature operates on
- ExternalEventSource — Feature for dragging events in from external sources
Configs
Configs are options you supply in a configuration object when creating an instance of this class-
Specify
falseto disallow creating events by drag gestures. -
Specify
falseto disallow dragging events to new times or days. -
This is configured as a DomHelper specification and is promoted to an
HTMLElementduring initialization. This element is moved between calendar event elements on hover in order to show drag handles on the event under the mouse. -
The text to display as a hint for creating recurring events during drag. This tip is displayed in the tooltip in the same place as the recurrence summary (when there is no recurrence to display).
-
By default, when an event is dragged from an external source, the event is removed from the source EventStore. Configure this as
falseto leave the event in place to allow for the dragging in of the same event repeatedly.Has a corresponding runtime removeFromExternalStore property.
-
Specify
falseto disallow dragging the edges of events to change their start or end. -
The tooltip to display during a drag create process. Disabled by default, set to
true, or provide a tooltip / config object, to enable it.
Properties
Properties are getters/setters or publicly accessible variables on this class-
Identifies an object as an instance of CalendarDrag class, or subclass thereof.
-
By default, when an event is dragged from an external source, the event is removed from the source EventStore. Configure this as
falseto leave the event in place to allow for the dragging in of the same event repeatedly.Has a corresponding removeFromExternalStore config.
-
Identifies an object as an instance of CalendarDrag class, or subclass thereof.