Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit c17b3eb

Browse files
committed
check data before append html
1 parent 154dd01 commit c17b3eb

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

app/code/Magento/Search/view/frontend/web/form-mini.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -286,16 +286,17 @@ define([
286286
$.getJSON(this.options.url, {
287287
q: value
288288
}, $.proxy(function (data) {
289-
$.each(data, function (index, element) {
290-
var html;
291-
element.index = index;
292-
html = template({
293-
data: element
289+
if (data.length) {
290+
$.each(data, function (index, element) {
291+
var html;
292+
293+
element.index = index;
294+
html = template({
295+
data: element
296+
});
297+
dropdown.append(html);
294298
});
295-
dropdown.append(html);
296-
});
297299

298-
if (dropdown.has('li').length) {
299300
this.responseList.indexList = this.autoComplete.html(dropdown)
300301
.css(clonePosition)
301302
.show()
@@ -322,7 +323,8 @@ define([
322323
this.element.attr('aria-activedescendant', $(e.target).attr('id'));
323324
}.bind(this))
324325
.on('mouseout', function (e) {
325-
if (!this._getLastElement() && this._getLastElement().hasClass(this.options.selectClass)) {
326+
if (!this._getLastElement() &&
327+
this._getLastElement().hasClass(this.options.selectClass)) {
326328
$(e.target).removeClass(this.options.selectClass);
327329
this._resetResponseList(false);
328330
}

0 commit comments

Comments
 (0)