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

Event Calendar Delete Confirmation?

Asked by Anonymous
20 days 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]
20 days 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
20 days ago.

Thank you!

New Reply
This reply is
Attachments:
or drop files here
Your name (optional):