From c70de71cffef3d046b188655f007437f0043d741 Mon Sep 17 00:00:00 2001 From: snt Date: Wed, 18 Feb 2026 17:11:47 +0100 Subject: [PATCH] [ADD] website_sale_aplicoop: re-implement clear search button MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added × button to clear the search input field. When clicked: - Clears the search text - Updates lastSearchValue to prevent polling false-positive - Calls infiniteScroll.resetWithFilters() to reload all products from server - Maintains current category filter - Returns focus to search input The button appears when text is entered and hides when search is empty. --- .../static/src/js/realtime_search.js | 34 +++++++++++++++---- .../views/website_templates.xml | 3 -- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/website_sale_aplicoop/static/src/js/realtime_search.js b/website_sale_aplicoop/static/src/js/realtime_search.js index 0cdc792..c096bac 100644 --- a/website_sale_aplicoop/static/src/js/realtime_search.js +++ b/website_sale_aplicoop/static/src/js/realtime_search.js @@ -156,12 +156,13 @@ JSON.stringify(self.lastCategoryValue) ); - // Clear search button - DISABLED FOR NOW - // TODO: Re-implement without causing initialization issues - /* + // Clear search button self.clearSearchBtn = document.getElementById("clear-search-btn"); if (self.clearSearchBtn) { + console.log("[realtimeSearch] Clear search button found, attaching listeners"); + // Show/hide button based on input content (passive, no filtering) + // This listener is separate from the filtering listener self.searchInput.addEventListener("input", function () { if (self.searchInput.value.trim().length > 0) { self.clearSearchBtn.style.display = "block"; @@ -173,20 +174,39 @@ // Clear search when button clicked self.clearSearchBtn.addEventListener("click", function (e) { e.preventDefault(); + e.stopPropagation(); console.log("[realtimeSearch] Clear search button clicked"); + + // Clear the input self.searchInput.value = ""; self.clearSearchBtn.style.display = "none"; + + // Update last stored value to prevent polling from detecting "change" + self.lastSearchValue = ""; + + // Reset infinite scroll to reload all products from server + if ( + window.infiniteScroll && + typeof window.infiniteScroll.resetWithFilters === "function" + ) { + console.log( + "[realtimeSearch] Resetting infinite scroll to show all products" + ); + window.infiniteScroll.resetWithFilters("", self.lastCategoryValue); + } else if (!self.isInitializing) { + // Fallback: filter locally + self._filterProducts(); + } + + // Focus back to search input self.searchInput.focus(); - // Trigger input event to update search results - self.searchInput.dispatchEvent(new Event("input", { bubbles: true })); }); - // Initial check + // Initial check - don't show if empty if (self.searchInput.value.trim().length > 0) { self.clearSearchBtn.style.display = "block"; } } - */ // Prevent form submission completely var form = self.searchInput.closest("form"); diff --git a/website_sale_aplicoop/views/website_templates.xml b/website_sale_aplicoop/views/website_templates.xml index 4a89ee7..49aa797 100644 --- a/website_sale_aplicoop/views/website_templates.xml +++ b/website_sale_aplicoop/views/website_templates.xml @@ -473,15 +473,12 @@
- -