From 016d802a106ed33e18f16b4a63e804555eac6ab5 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 29 Mar 2022 23:49:06 +1100 Subject: [PATCH] Fixes for input autofocus, etc --- .../static/script/inventree/inventree.js | 2 +- InvenTree/templates/js/translated/search.js | 18 ++++++++++++++---- InvenTree/templates/search.html | 8 ++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/InvenTree/InvenTree/static/script/inventree/inventree.js b/InvenTree/InvenTree/static/script/inventree/inventree.js index f991ed3766..efad99c3ec 100644 --- a/InvenTree/InvenTree/static/script/inventree/inventree.js +++ b/InvenTree/InvenTree/static/script/inventree/inventree.js @@ -157,7 +157,7 @@ function inventreeDocReady() { }); // Calbacks for search panel - $('#offcanvas-search').on('show.bs.offcanvas', openSearchPanel); + $('#offcanvas-search').on('shown.bs.offcanvas', openSearchPanel); $('#offcanvas-search').on('hidden.bs.offcanvas', closeSearchPanel); // Callbacks for notifications panel diff --git a/InvenTree/templates/js/translated/search.js b/InvenTree/templates/js/translated/search.js index facfb884ff..a412a11b48 100644 --- a/InvenTree/templates/js/translated/search.js +++ b/InvenTree/templates/js/translated/search.js @@ -27,16 +27,23 @@ function openSearchPanel() { clearSearchResults(); - // Finally, grab keyboard focus in the search bar - panel.find('#search-input').focus(); - panel.find('#search-input').on('keyup change', searchTextChanged); // Callback for "clear search" button - panel.find('#search-clear').click(function() { + panel.find('#search-clear').click(function(event) { + + // Prevent this button from actually submitting the form + event.preventDefault(); + panel.find('#search-input').val(''); clearSearchResults(); }); + + // Callback for the "close search" button + panel.find('#search-close').click(function(event) { + // Prevent this button from actually submitting the form + event.preventDefault(); + }); } var searchRequests = []; @@ -211,6 +218,9 @@ function clearSearchResults() { // Delete any existing search results panel.find('#search-results').empty(); + + // Finally, grab keyboard focus in the search bar + panel.find('#search-input').focus(); } diff --git a/InvenTree/templates/search.html b/InvenTree/templates/search.html index 48f30194ad..b43175b4b0 100644 --- a/InvenTree/templates/search.html +++ b/InvenTree/templates/search.html @@ -5,13 +5,13 @@
{% csrf_token %}
- - + +