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 @@
- -