From 9ab16806f231bc2ac40ac3761180015b76b5e596 Mon Sep 17 00:00:00 2001 From: Andreas Roussos Date: Wed, 24 Jul 2024 22:59:45 +0000 Subject: [PATCH] Bug 33668: (follow-up) Modify the JS logic behind the 'Clear search' button In the existing code, the 'Clear search' button would hide itself after clearing anything typed at the search . This patch adjusts the JavaScript logic so that when the page first loads and the search is empty, the 'Clear search' button will not be displayed at all. The 'X' (Clear search) button will only appear once the user has typed something in the search area. Test plan: 1) Apply the patch. 2) Do a hard refresh (CTRL+F5) on the OPAC main page to reload all JS assets. 3) Notice that the 'Clear search' button is not displayed. 4) Try to search for something -> the button appears! 5) Use the 'X' button to clear your search -> the search terms are cleared and the 'X' button hides itself! --- koha-tmpl/opac-tmpl/bootstrap/js/global.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/global.js b/koha-tmpl/opac-tmpl/bootstrap/js/global.js index 0f939c3d24..8a69c16615 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/js/global.js +++ b/koha-tmpl/opac-tmpl/bootstrap/js/global.js @@ -254,13 +254,14 @@ function setPlaceholder(){ let clearButton = $(''); $("#translControl1").attr("placeholder", search_placeholder).after(clearButton); + clearButton.hide(); clearButton.click(function() { $("#translControl1").val('').focus(); $(this).hide(); }); - $("#translControl1").on('input', function() { + $("#translControl1").on('input focus', function() { if ($(this).val() !== '') { clearButton.show(); } else { -- 2.39.2