From 439906e65bb663a7a39bc607179b84f407ea3458 Mon Sep 17 00:00:00 2001 From: daniel tabarcea Date: Mon, 19 Mar 2018 15:32:34 +0200 Subject: [PATCH 1/2] Fixed warnings about selected options not found CH #4712 --- etools-multi-selection-menu.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etools-multi-selection-menu.html b/etools-multi-selection-menu.html index e7446c7..7cc6ea5 100644 --- a/etools-multi-selection-menu.html +++ b/etools-multi-selection-menu.html @@ -314,7 +314,7 @@ // This observer makes sure request for missing option is triggered only after the url is set also. // notFoundOption is actually this.selected _notFoundOptionsAndUrlChanged: function() { - if (this.notFoundOptions) { + if (Array.isArray(this.notFoundOptions) && this.notFoundOptions.length > 0) { this._handleSelectedNotFoundInOptions(this.notFoundOptions); } }, From 4713547d73c715fb2c50f537d142a22e3dad26e5 Mon Sep 17 00:00:00 2001 From: daniel tabarcea Date: Mon, 19 Mar 2018 18:13:50 +0200 Subject: [PATCH 2/2] added method to check for empty arrays --- behaviors/common-behavior.html | 4 ++++ etools-multi-selection-menu.html | 8 ++++---- etools-single-selection-menu.html | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/behaviors/common-behavior.html b/behaviors/common-behavior.html index 94d3381..3154ad3 100644 --- a/behaviors/common-behavior.html +++ b/behaviors/common-behavior.html @@ -402,6 +402,10 @@ return true; } return false; + }, + + arrayNotEmpty(arr) { + return Array.isArray(arr) && arr.length; } }; diff --git a/etools-multi-selection-menu.html b/etools-multi-selection-menu.html index 7cc6ea5..3428d48 100644 --- a/etools-multi-selection-menu.html +++ b/etools-multi-selection-menu.html @@ -314,7 +314,7 @@ // This observer makes sure request for missing option is triggered only after the url is set also. // notFoundOption is actually this.selected _notFoundOptionsAndUrlChanged: function() { - if (Array.isArray(this.notFoundOptions) && this.notFoundOptions.length > 0) { + if (this.arrayNotEmpty(this.notFoundOptions)) { this._handleSelectedNotFoundInOptions(this.notFoundOptions); } }, @@ -330,7 +330,7 @@ }, _updateAfterMissingOptionsReceived: function(detail) { var selectedItems; - if (Array.isArray(detail) && detail.length) { + if (this.arrayNotEmpty(detail)) { selectedItems = detail; } else { selectedItems = [detail]; @@ -410,7 +410,7 @@ _selectedItemsDisplayHasChanged: function(e) { e.stopImmediatePropagation(); // hide/show placeholder - if (this.selectedItems instanceof Array && this.selectedItems.length > 0) { + if (this.arrayNotEmpty(this.selectedItems)) { this.set('_hidePlaceholder', true); } else { this.set('_hidePlaceholder', false); @@ -418,7 +418,7 @@ }, // Use of this method covers a corner case _getSelectedClass: function(item) { - if (this.selectedValues instanceof Array && this.selectedValues.length > 0) { + if (this.arrayNotEmpty(this.selectedValues)) { return this.selectedValues.indexOf(item[this.optionValue].toString()) > -1 ? 'iron-selected' : ''; } return ''; diff --git a/etools-single-selection-menu.html b/etools-single-selection-menu.html index ebff32a..1c9e727 100644 --- a/etools-single-selection-menu.html +++ b/etools-single-selection-menu.html @@ -243,7 +243,7 @@ }, _updateAfterMissingOptionsReceived: function(detail) { var selectedItem; - if (Array.isArray(detail) && detail.length) { + if (this.arrayNotEmpty(detail)) { selectedItem = detail[0]; } else { selectedItem = detail;