Skip to content

Commit

Permalink
fix(ujs): guard for submitter on data-confirm
Browse files Browse the repository at this point in the history
  • Loading branch information
joelmoss committed Apr 23, 2024
1 parent 52a5453 commit c2c7383
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions lib/proscenium/libs/ujs/data_confirm.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
export default class DataConfirm {
onSubmit = event => {
if (!event.target.matches('[data-turbo=true]') && 'confirm' in event.submitter.dataset) {
const v = event.submitter.dataset.confirm
onSubmit = (event) => {
if (
!event.target.matches("[data-turbo=true]") &&
event.submitter &&
"confirm" in event.submitter.dataset
) {
const v = event.submitter.dataset.confirm;

if (v !== 'false' && !confirm(v === 'true' || v === '' ? 'Are you sure?' : v)) {
event.preventDefault()
event.stopPropagation()
event.stopImmediatePropagation()
return false
if (
v !== "false" &&
!confirm(v === "true" || v === "" ? "Are you sure?" : v)
) {
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
return false;
}
}

return true
}
return true;
};
}

0 comments on commit c2c7383

Please sign in to comment.