diff --git a/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js b/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js
index 9dd6f4b561166..87e2bfcf77ae6 100644
--- a/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js
+++ b/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js
@@ -53,21 +53,30 @@ $(() => {
}
$(document).on("click.zf.trigger", (event) => {
- const target = `#${$(event.target).data("dialogOpen")}`;
- const redirectUrl = $(event.target).data("redirectUrl");
+ // Try to get the directly or find the closest parent
+ const $target = $(event.target).closest("a");
- if (!target || !redirectUrl) {
- return;
+ // Check if an was found
+ if (!$target) {
+ return;
}
+
+
+ const dialogTarget = `#${$target.data("dialog-open")}`;
+ const redirectUrl = $target.data("redirectUrl");
+ if (!dialogTarget || !redirectUrl) {
+ return;
+ }
+
$("").
attr("id", "redirect_url").
attr("name", "redirect_url").
attr("value", redirectUrl).
- appendTo(`${target} form`);
+ appendTo(`${dialogTarget} form`);
- $(`${target} a`).attr("href", (index, href) => {
- const querystring = jQuery.param({ "redirect_url": redirectUrl });
+ $(`${dialogTarget} a`).attr("href", (index, href) => {
+ const querystring = jQuery.param({"redirect_url": redirectUrl});
return href + (href.match(/\?/) ? "&" : "?") + querystring;
});
});