From 144e91fc256d13b659a9804c687f4bd9d3bc9272 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Thu, 25 May 2023 15:58:26 +0000 Subject: [PATCH] Bug 27378: Prevent delete confirmation from duplicating Previously, if the "Add new code" button was clicked multipe times in the CookieConsentedJS editor and then those new items were deleted, the confirmation alert would show multiple times. This was an incremental issue, i.e. if 4 new items were deleted, then the first of those would require 4 confirmations to delete, the second would require 3 and so on. This is now prevented by looping through all delete buttons and avoiding duplicating the event listeners --- .../prog/js/pages/preferences.js | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js index 6bde33bba4..fc72beff92 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js +++ b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js @@ -134,19 +134,24 @@ function addCollapseHandler() { // Add a handler for any consent delete links function addConsentDeleteHandler() { - // Don't duplicate click event handlers - const ev = $._data($('.consentDelete'), 'events'); - if (ev && ev.click) { - return; - } - $('.consentDelete').on('click', function (e) { - e.preventDefault(); - const target = $(this).data('target'); - const proceed = confirm(__('Are you sure you want to delete this consent item?')); - if (proceed) { - $('#' + target).remove(); + const deleteButtons = $('.consentDelete').map(function() { + return this + }).get(); + deleteButtons.forEach((deleteButton) => { + // Don't duplicate click event handlers + const ev = $._data($(deleteButton).get(0), 'events'); + if (ev && ev.click) { + return; } - }); + $(deleteButton).on('click', function (e) { + e.preventDefault(); + const target = $(this).data('target'); + const proceed = confirm(__('Are you sure you want to delete this consent item?')); + if (proceed) { + $('#' + target).remove(); + } + }); + }) } $( document ).ready( function () { -- 2.37.1 (Apple Git-137.1)