There are a couple of issues with this example:
1. If you set args.async = true, you must call args.loaded() in every code path. Otherwise the dragging operation will remain active.
- The first "if" block returns without calling args.loaded().
- If you cancel the modal dialog (modal.canceled === true) it doesn't call args.loaded().
2. If you want to cancel the default action, you must call args.preventDefault() before args.loaded().
3. The JavaScript Date objects can't be compared using ">" operator. You need to compare the millisecond value returned by getTime().
Direct comparison using < > and === operators is only supported for DayPilot.Date objects. DayPilot.Date was intentionally designed to work this way:
https://api.daypilot.org/daypilot-date-class/
You could rewrite it like this to make it work:
onEventMove: async (args) => {
const groupSplit = args.newResource.split('-');
if (Number(args.e.data.group_id) !== Number(groupSplit[1]) ){
args.preventDefault();
DayPilot.Modal.alert('Error occurred while assigning the task. Please assign task to correct group.');
return;
}
if (DayPilot.Date.today() > args.newStart) {
args.async = true;
const modal = await DayPilot.Modal.confirm("Are you sure?");
if (modal.canceled) {
args.preventDefault();
}
else {
calendarApp.assignTaskDnD(args.e, args.newStart, args.newEnd, args.newResource, args);
}
args.loaded();
} else {
calendarApp.assignTaskDnD(args.e, args.newStart, args.newEnd, args.newResource, args);
}
},