From 4c2ed5a5f711eb504439399ee3d466820d431a3d Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Tue, 16 Aug 2022 14:13:15 +0000 Subject: [PATCH] [FIX] website: show icons in autocomplete results when no image defined Since [1] when the search bar was refactored, images can be displayed in the autocomplete results, and fallback icons are displayed instead of images for records that have no images. However, if no module that participates in the results provides actual images, then the fallback icons are not displayed at all. This commit makes the fallback icons displayed only based on the "Image" toggle option of the search bar. It also disables the hidden display options and enables the visible ones. Steps to reproduce: - Do NOT install website_sale (which is currently the only module that provides autocomplete results with images). - Drop a "Search" block. - Save. - Type a single letter in the search box. (e.g. "a") => Autocomplete results were displayed without their icons. [1]: https://github.com/odoo/odoo/commit/7559626c54e34b41e1549e28276a650accec6986 task-2951026 closes odoo/odoo#106953 X-original-commit: 4eecba4c8f5327fd1a137a8d88574c2b6a5eda05 Signed-off-by: Romain Derie (rde) --- .../website/static/src/snippets/s_searchbar/000.xml | 2 +- .../static/src/snippets/s_searchbar/options.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/addons/website/static/src/snippets/s_searchbar/000.xml b/addons/website/static/src/snippets/s_searchbar/000.xml index 03594e4f10f..77e41f66525 100644 --- a/addons/website/static/src/snippets/s_searchbar/000.xml +++ b/addons/website/static/src/snippets/s_searchbar/000.xml @@ -17,7 +17,7 @@
- + diff --git a/addons/website/static/src/snippets/s_searchbar/options.js b/addons/website/static/src/snippets/s_searchbar/options.js index d26fc7ddf79..3868525dd02 100644 --- a/addons/website/static/src/snippets/s_searchbar/options.js +++ b/addons/website/static/src/snippets/s_searchbar/options.js @@ -22,6 +22,18 @@ options.registry.SearchBar = options.Class.extend({ defaultOrder.click(); // close } }}); + + // Reset display options. + const displayOptions = new Set(); + for (const optionEl of this.$el[0].querySelectorAll('[data-dependencies="limit_opt"] [data-attribute-name^="display"]')) { + displayOptions.add(optionEl.dataset.attributeName); + } + const scopeName = this.$el[0].querySelector(`[data-set-search-type="${widgetValue}"]`).dataset.name; + for (const displayOption of displayOptions) { + this.$target[0].dataset[displayOption] = this.$el[0].querySelector( + `[data-attribute-name="${displayOption}"][data-dependencies="${scopeName}"]` + ) ? 'true' : ''; + } } },