From c17b3ebfd2ac922776def21eca730fd5ac57f353 Mon Sep 17 00:00:00 2001 From: crissanclick Date: Thu, 5 Oct 2017 20:02:33 +0200 Subject: [PATCH] check data before append html --- .../Search/view/frontend/web/form-mini.js | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Search/view/frontend/web/form-mini.js b/app/code/Magento/Search/view/frontend/web/form-mini.js index 3dd6e4741acf3..e8598f46eb5be 100644 --- a/app/code/Magento/Search/view/frontend/web/form-mini.js +++ b/app/code/Magento/Search/view/frontend/web/form-mini.js @@ -286,16 +286,17 @@ define([ $.getJSON(this.options.url, { q: value }, $.proxy(function (data) { - $.each(data, function (index, element) { - var html; - element.index = index; - html = template({ - data: element + if (data.length) { + $.each(data, function (index, element) { + var html; + + element.index = index; + html = template({ + data: element + }); + dropdown.append(html); }); - dropdown.append(html); - }); - if (dropdown.has('li').length) { this.responseList.indexList = this.autoComplete.html(dropdown) .css(clonePosition) .show() @@ -322,7 +323,8 @@ define([ this.element.attr('aria-activedescendant', $(e.target).attr('id')); }.bind(this)) .on('mouseout', function (e) { - if (!this._getLastElement() && this._getLastElement().hasClass(this.options.selectClass)) { + if (!this._getLastElement() && + this._getLastElement().hasClass(this.options.selectClass)) { $(e.target).removeClass(this.options.selectClass); this._resetResponseList(false); }