Skip to content

Commit

Permalink
frontend: don't trigger other event handlers if delete action cancell…
Browse files Browse the repository at this point in the history
…ed (#1657)

Otherwise, clicking the delete button beside a custom command response and then cancelling it at the confirmation popup (erroneously) still deletes the response.

An analysis of the issue: the confirmation prompt is triggered when any element with the `btn-danger` class is clicked. If confirmation fails, preventDefault() and stopPropagation() are called, which are typically sufficient to prevent the deletion from going through. But in the case where the deletion is performed in another click event handler -- which is the case for the implementation of deleting custom command responses -- stopPropagation() will (roughly speaking) only prevent event handlers on parent elements from triggering. That is, event handlers registered for the same element will still fire, hence the bug.

Calling stopImmediatePropagation() will correctly stop the event handlers for the same element from triggering.
  • Loading branch information
jo3-l authored May 30, 2024
1 parent c21a803 commit 2a58570
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions frontend/static/js/spongebob.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ function formSubmissionEvents() {
// console.log("aaaaa", evt, evt.preventDefault);
if (!confirm("Are you sure you want to do this?")) {
evt.preventDefault(true);
evt.stopPropagation();
evt.stopImmediatePropagation();
}
// alert("aaa")
}
Expand Down Expand Up @@ -545,13 +545,13 @@ function formSubmissionEvents() {
if (title !== undefined) {
if (!confirm("Deleting " + title + ". Are you sure you want to do this?")) {
event.preventDefault(true);
event.stopPropagation();
event.stopImmediatePropagation();
return;
}
} else {
if (!confirm("Are you sure you want to do this?")) {
event.preventDefault(true);
event.stopPropagation();
event.stopImmediatePropagation();
return;
}
}
Expand Down

0 comments on commit 2a58570

Please sign in to comment.