Skip to content

Commit

Permalink
Merge pull request #122 from unicef-polymer/fix-missing-options-warnings
Browse files Browse the repository at this point in the history
Fix warnings about selected options not found
  • Loading branch information
daniel-tabarcea authored Mar 21, 2018
2 parents d1e70fc + 4713547 commit a4f4766
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions behaviors/common-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@
return true;
}
return false;
},

arrayNotEmpty(arr) {
return Array.isArray(arr) && arr.length;
}

};
Expand Down
8 changes: 4 additions & 4 deletions etools-multi-selection-menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
Expand All @@ -330,7 +330,7 @@
},
_updateAfterMissingOptionsReceived: function(detail) {
var selectedItems;
if (Array.isArray(detail) && detail.length) {
if (this.arrayNotEmpty(detail)) {
selectedItems = detail;
} else {
selectedItems = [detail];
Expand Down Expand Up @@ -411,15 +411,15 @@
_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);
}
},
// 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 '';
Expand Down
2 changes: 1 addition & 1 deletion etools-single-selection-menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a4f4766

Please sign in to comment.