From 9ca98191a500e1cc4262d2b1b1084467fc64bd35 Mon Sep 17 00:00:00 2001 From: Renato Date: Tue, 15 Oct 2024 06:40:29 -0300 Subject: [PATCH] fix: redirect user to the intented page --- .../decidim/append_redirect_url_to_modals.js | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) 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 558c011efdc8..33f10c6f044b 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,20 +53,29 @@ $(() => { } $(document).on("click.zf.trigger", (event) => { - const target = `#${$(event.target).data("open")}`; - const redirectUrl = $(event.target).data("redirectUrl"); + // Try to get the directly or find the closest parent + let $target = $(event.target); + if (!$target.is('a')) { + $target = $target.closest('a'); // Find the closest parent if the click is not directly on an + } + + // Check if an was found + if ($target.length) { + const dialogTarget = `#${$target.data("dialog-open")}`; + const redirectUrl = $target.data("redirectUrl"); - if (target && redirectUrl) { - $(""). - attr("id", "redirect_url"). - attr("name", "redirect_url"). - attr("value", redirectUrl). - appendTo(`${target} form`); + if (dialogTarget && redirectUrl) { + $("") + .attr("id", "redirect_url") + .attr("name", "redirect_url") + .attr("value", redirectUrl) + .appendTo(`${dialogTarget} form`); - $(`${target} a`).attr("href", (index, href) => { - const querystring = jQuery.param({"redirect_url": redirectUrl}); - return href + (href.match(/\?/) ? "&" : "?") + querystring; - }); + $(`${dialogTarget} a`).attr("href", (index, href) => { + const querystring = jQuery.param({"redirect_url": redirectUrl}); + return href + (href.match(/\?/) ? "&" : "?") + querystring; + }); + } } });