diff --git a/changedetectionio/static/js/search-modal.js b/changedetectionio/static/js/search-modal.js index fe96186b5..ac4065332 100644 --- a/changedetectionio/static/js/search-modal.js +++ b/changedetectionio/static/js/search-modal.js @@ -7,7 +7,6 @@ // The Search button is rendered in the left rail and the mobile drawer. const openSearchButtons = document.querySelectorAll('.js-open-search-modal'); const closeSearchButton = document.getElementById('close-search-modal'); - const searchForm = document.getElementById('search-form'); const searchInput = document.getElementById('search-modal-input'); if (!searchModal || openSearchButtons.length === 0) { @@ -93,43 +92,8 @@ } }); - // Handle Enter key in search input - if (searchInput) { - searchInput.addEventListener('keydown', function(e) { - if (e.key === 'Enter') { - e.preventDefault(); - if (searchForm) { - // Trigger form submission programmatically - searchForm.dispatchEvent(new Event('submit')); - } - } - }); - } - - // Handle form submission - if (searchForm) { - searchForm.addEventListener('submit', function(e) { - e.preventDefault(); - - // Get form data - const formData = new FormData(searchForm); - const searchQuery = formData.get('q'); - const tags = formData.get('tags'); - - // Build URL - const params = new URLSearchParams(); - if (searchQuery) { - params.append('q', searchQuery); - } - if (tags) { - params.append('tags', tags); - } - - // Navigate to search results (always redirect to watchlist home) - // Use base_path if available (for sub-path deployments like /enlighten-richerx) - const basePath = typeof base_path !== 'undefined' ? base_path : ''; - window.location.href = basePath + '/?' + params.toString(); - }); - } + // Submission is left to the browser: the form carries a server-rendered action + // (correct under a reverse-proxy sub-path) and Enter in the input triggers implicit + // submission via the footer's submit button, which also runs `required` validation. }); })(); diff --git a/changedetectionio/templates/base.html b/changedetectionio/templates/base.html index 9c075bcca..93ae11d14 100644 --- a/changedetectionio/templates/base.html +++ b/changedetectionio/templates/base.html @@ -317,11 +317,13 @@ diff --git a/changedetectionio/tests/test_search.py b/changedetectionio/tests/test_search.py index e89b7a14a..df4560699 100644 --- a/changedetectionio/tests/test_search.py +++ b/changedetectionio/tests/test_search.py @@ -71,3 +71,12 @@ def test_search_in_tag_limit(client, live_server, measure_memory_usage, datastor assert urls[0].split(' ')[0].encode('utf-8') in res.data, urls[0].encode('utf-8') assert urls[1].split(' ')[0].encode('utf-8') not in res.data, urls[0].encode('utf-8') + +def test_search_modal_form_action(client, live_server, measure_memory_usage, datastore_path): + # The search modal submits as a plain GET form, so its action has to carry the + # reverse-proxy sub-path (SCRIPT_NAME), otherwise search jumps to the host root. + res = client.get(url_for("watchlist.index")) + assert b'
' in res.data + + res = client.get("/", base_url="http://localhost/sub-path") + assert b'' in res.data