From 1692be0babab0972cdde73d521b384ec14ea18d9 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 When the OPAC main page first loads and the search is empty, the 'X' (Clear search) button is displayed anyway. This can potentially cause some UX confusion involving the presence of an 'X' button inside an otherwise empty search box. This patch fixes that in a way that doesn't affect the display of the 'X' button after performing an actual search. Test plan: 1) Without this patch applied, visit the OPAC main page. Notice that even though there's nothing in the search box yet, the 'Clear search' button is displayed anyway. 2) Apply this patch / reload all JavaScript assets (CTRL+F5). 3) Notice that the 'Clear search' button is no longer visible when the search box is empty. 4) Type something in the search box: notice that the 'X' button appears. 5) Use the 'X' button to clear your search: the search terms are cleared and the 'X' button hides itself. 6) Perform an actual search and in the results page notice that the 'X' button remains visible. Signed-off-by: Roman Dolny --- koha-tmpl/opac-tmpl/bootstrap/js/global.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/global.js b/koha-tmpl/opac-tmpl/bootstrap/js/global.js index 0f939c3d24..5fbbc2c077 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/js/global.js +++ b/koha-tmpl/opac-tmpl/bootstrap/js/global.js @@ -255,6 +255,10 @@ function setPlaceholder(){ $("#translControl1").attr("placeholder", search_placeholder).after(clearButton); + if ($("#translControl1").val() == '') { + clearButton.hide(); + } + clearButton.click(function() { $("#translControl1").val('').focus(); $(this).hide(); -- 2.39.2