search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Event Calendar Delete Confirmation?

Asked by Anonymous
1 month ago.

Hello,

I’m trying to ask for confirmation before deleting an event using the Modal function.

Right now I accomplish the confirmation with:

onEventDelete: async (args) => {
 if(!confirm("Are you sure you want to delete this event?")){
  args.preventDefault();
 }
}

But when I try it with a Modal function, it doesn’t work.

onEventDelete: async (args) => {
 const dlt = await DayPilot.Modal.confirm("Are you sure you want to delete this event?");
 if(dlt.canceled){
  args.preventDefault();
 }
}
Answer posted by Dan Letecky [DayPilot]
1 month ago.

When you use an async function in the event handler, calling args.preventDefault() after await has no effect as the processing continues immediately (before args.preventDefault() gets called).

You need to switch the logic and delete the event using events.remove():

onEventDelete: async (args) => {
 args.preventDefault();
 const dlt = await DayPilot.Modal.confirm("Are you sure you want to delete this event?");
 if(!dlt.canceled){
   dp.events.remove(args.e);
 }
}
Comment posted by Anonymous
1 month ago.

Thank you!

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.