Topic: Showing a custom confirmation before calendar event deletion
MarkoDev
free
asked 1 week ago
I need a confirmation dialog before removing an appointment. The calendar performs its default action while my modal is still open.
Can the action handler defer that behavior?
Arkadiusz Idzikowski
staff
answered 1 week ago
The cancellation is after await, so the calendar can perform its default deletion before that line runs. Move it to the first line and capture the selected appointment before opening the dialog.
With this ordering, a canceled dialog never changes your event collection. Please also test confirming deletion to check that only the selected appointment is removed.
async onDelete(action: MdbCalendarEventAction) {
action.preventDefault();
const appointment = action.event;
const confirmed = await this.confirmDelete();
if (confirmed) {
this.events = this.events.filter(
event => event.id !== appointment.id
);
}
}
Arkadiusz Idzikowski
staff
answered 1 week ago
Call action.preventDefault() immediately in the calendar's delete callback, before awaiting your confirmation dialog. This stops the built in action from proceeding while the user is deciding. Keep action.event available for the eventual confirmed operation.
If confirmation is accepted, remove that appointment through your application's event collection or the plugin's deletion API. A dismissal should leave the collection unchanged. Please include the delete handler and the code that updates the event collection if the appointment disappears before confirmation despite canceling the action.
https://mdbootstrap.com/docs/angular/plugins/calendar/
MarkoDev free commented 1 week ago
I added preventDefault(), but the appointment still disappears while the confirmation is open. Here is the handler. confirmDelete() returns a Promise that resolves when our dialog closes; canceling the dialog should leave the appointment untouched.
async onDelete(action: MdbCalendarEventAction) {
const confirmed = await this.confirmDelete();
action.preventDefault();
if (confirmed) {
this.events = this.events.filter(
event => event.id !== action.event.id
);
}
}
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Free
- Premium support: No
- Technology: MDB Angular
- MDB Version: MDB5 9.1.0
- Device: Laptop
- Browser: Firefox
- OS: macOS
- Provided sample code: No
- Provided link: No