From 0ce05c540d25ebc4bd589c1e2436ee2aa642ccf5 Mon Sep 17 00:00:00 2001 From: "Laurent Stukkens (LTU)" Date: Fri, 29 May 2020 09:21:25 +0000 Subject: [PATCH] [FIX] website_sale: prevent search bar bug Issue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When pressing UP or DOWN arrow in search bar with empty text a traceback occurs. Step to Reproduce - Install website_sale "eCommerce" application - Go to Website - Go to Shop - Click in Search Bar - Press Up or Down Key Cause When no text is entered in the search bar, the $menu is undefined so trying to access children causes the error Solution Test that $menu is defined prior to try accessing its children task id-2252923 closes odoo/odoo#52161 Forward-port-of: #51920 X-original-commit: 30785e68852fa3cd18be11fcbaad4e886d01301c Signed-off-by: Jérémy Kersten (jke) --- .../static/src/snippets/s_products_searchbar/000.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/website_sale/static/src/snippets/s_products_searchbar/000.js b/addons/website_sale/static/src/snippets/s_products_searchbar/000.js index 5117d405a05..2aaafca20b6 100644 --- a/addons/website_sale/static/src/snippets/s_products_searchbar/000.js +++ b/addons/website_sale/static/src/snippets/s_products_searchbar/000.js @@ -123,12 +123,12 @@ publicWidget.registry.productsSearchBar = publicWidget.Widget.extend({ this._render(); break; case $.ui.keyCode.UP: - ev.preventDefault(); - this.$menu.children().last().focus(); - break; case $.ui.keyCode.DOWN: ev.preventDefault(); - this.$menu.children().first().focus(); + if (this.$menu) { + let $element = ev.which === $.ui.keyCode.UP ? this.$menu.children().last() : this.$menu.children().first(); + $element.focus(); + } break; } },