Skip to content

Commit fac04b8

Browse files
committed
bug EasyCorp#7484 Fix modals of actions with confirmation messages and rendered as forms (javiereguiluz)
This PR was merged into the 4.x branch. Discussion ---------- Fix modals of actions with confirmation messages and rendered as forms Fixes EasyCorp#7483. Commits ------- 78388c7 Fix modals of actions with confirmation messages and rendered as forms
2 parents 1964efe + 78388c7 commit fac04b8

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

assets/js/app.js

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -440,20 +440,33 @@ class App {
440440
modalButton.addEventListener(
441441
'click',
442442
() => {
443-
// check if this is a POST action (like DELETE with formaction) or GET (link href)
443+
// Case 1: POST action with formaction (like DELETE with CSRF token)
444444
const formAction = actionElement.getAttribute('formaction');
445-
446445
if (formAction) {
447-
// POST action: use the hidden form with CSRF token (like DELETE)
448446
const form = document.querySelector('#action-confirmation-form');
449447
form.setAttribute('action', formAction);
450448
form.submit();
451-
} else {
452-
// GET action: navigate to the href URL
453-
const href = actionElement.getAttribute('href');
454-
if (href) {
455-
window.location.href = href;
456-
}
449+
return;
450+
}
451+
452+
// Case 2: dropdown action rendered as form (data-ea-action-form-id)
453+
const actionFormId = actionElement.getAttribute('data-ea-action-form-id');
454+
if (actionFormId) {
455+
document.getElementById(actionFormId).submit();
456+
return;
457+
}
458+
459+
// Case 3: standalone button inside a <form> (renderAsForm)
460+
const parentForm = actionElement.closest('form');
461+
if (parentForm && parentForm.hasAttribute('action')) {
462+
parentForm.submit();
463+
return;
464+
}
465+
466+
// Case 4: GET action with href
467+
const href = actionElement.getAttribute('href');
468+
if (href) {
469+
window.location.href = href;
457470
}
458471
},
459472
{ once: true }
@@ -609,17 +622,25 @@ class App {
609622

610623
#createActionHandlers() {
611624
// handle form submissions via data attribute (replaces inline onclick handlers)
625+
// skip elements with confirmation modals (handled by #createActionConfirmationModals)
612626
document.querySelectorAll('[data-ea-action-form-id]').forEach((element) => {
613627
element.addEventListener('click', (event) => {
628+
if (element.hasAttribute('data-action-confirmation')) {
629+
return;
630+
}
614631
event.preventDefault();
615632
const formId = element.getAttribute('data-ea-action-form-id');
616633
document.getElementById(formId).submit();
617634
});
618635
});
619636

620637
// handle navigation via data attribute (replaces inline onclick handlers)
638+
// skip elements with confirmation modals (handled by #createActionConfirmationModals)
621639
document.querySelectorAll('[data-ea-action-url]').forEach((element) => {
622640
element.addEventListener('click', (event) => {
641+
if (element.hasAttribute('data-action-confirmation')) {
642+
return;
643+
}
623644
event.preventDefault();
624645
window.location = element.getAttribute('data-ea-action-url');
625646
});
Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/entrypoints.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"/app.98533a09.css"
66
],
77
"js": [
8-
"/app.8f681b52.js"
8+
"/app.eff2bb42.js"
99
]
1010
},
1111
"form": {

public/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"app.css": "app.98533a09.css",
3-
"app.js": "app.8f681b52.js",
3+
"app.js": "app.eff2bb42.js",
44
"form.js": "form.5bccac01.js",
55
"page-layout.js": "page-layout.6e9fe55d.js",
66
"page-color-scheme.js": "page-color-scheme.e3fe1a0a.js",

0 commit comments

Comments
 (0)