diff --git a/behaviors/common-behavior.html b/behaviors/common-behavior.html index afb8d69..fa7e793 100644 --- a/behaviors/common-behavior.html +++ b/behaviors/common-behavior.html @@ -406,6 +406,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 28e7af1..bda5431 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 (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]; @@ -411,7 +411,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); @@ -419,7 +419,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 f4c7d9c..092c69c 100644 --- a/etools-single-selection-menu.html +++ b/etools-single-selection-menu.html @@ -244,7 +244,7 @@ }, _updateAfterMissingOptionsReceived: function(detail) { var selectedItem; - if (Array.isArray(detail) && detail.length) { + if (this.arrayNotEmpty(detail)) { selectedItem = detail[0]; } else { selectedItem = detail;