From ea1f966b9cc064c3ae46d0dc257e8e0adf8adb24 Mon Sep 17 00:00:00 2001 From: Adrian Hangan Date: Fri, 3 Mar 2017 15:36:14 +0200 Subject: [PATCH 1/2] changing selected values fix --- demo/demo-custom-objects-as-options.html | 10 +++++----- demo/index.html | 8 ++++---- etools-searchable-multiselection-menu.html | 19 +++++++++++++++---- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/demo/demo-custom-objects-as-options.html b/demo/demo-custom-objects-as-options.html index a72abad..5caba65 100644 --- a/demo/demo-custom-objects-as-options.html +++ b/demo/demo-custom-objects-as-options.html @@ -26,7 +26,7 @@

Multiple selection, custom objects as options

Custom objects as options and selected property with no change events

-

SelectedID: [[selectedId]]

+

SelectedIDs: [[_returnIdsString(selectedIds)]]

Custom objects as options and selected property with no change events this.set('customObjOptions', this.generateOptions()); }.bind(this), 3000); - setTimeout(function() { - this.set('selectedIds', null); - }.bind(this), 7000); + // setTimeout(function() { + // this.set('selectedIds', null); + // }.bind(this), 7000); }, _returnIdsString: function(vals) { diff --git a/demo/index.html b/demo/index.html index 086da49..cdeb978 100644 --- a/demo/index.html +++ b/demo/index.html @@ -28,7 +28,7 @@

etools-searchable-multiselection-menu demo

-

Single selection, with search

+

Custom objects as options. You can specify value and label properties from object option to be used.

@@ -141,13 +141,13 @@

Custom objects as options. You can specify value and label properties from o -

Readonly state

+
diff --git a/etools-searchable-multiselection-menu.html b/etools-searchable-multiselection-menu.html index fcba2c5..412f583 100644 --- a/etools-searchable-multiselection-menu.html +++ b/etools-searchable-multiselection-menu.html @@ -722,16 +722,27 @@ } }, - _updateSelected: function(selectedValues) { + _updateSelected: function(selectedValues, oldSelectedValues) { if (JSON.stringify(selectedValues) === JSON.stringify(this._prevSelectedValues)) { return; } this.debounce('updateSelectedValue', function() { - if (!this.updateSelected || !selectedValues || - Array.isArray(selectedValues) && selectedValues.length === 0) { - // do not update selected value + if (!this.updateSelected) { return; } + if (!this.multi) { + if (!selectedValues && !oldSelectedValues) { + return; + } + } else { + if (selectedValues === null && Array.isArray(this._prevSelectedValues) && this._prevSelectedValues.length === 0) { + return; + } + if (!this._prevSelectedValues && (!selectedValues || (Array.isArray(selectedValues) && selectedValues.length === 0))) { + return; + } + } + var selectedVals = null; if (this.multi && Array.isArray(selectedValues)) { // multiselection From 0624d16477db634955235b01c76dfcc632c123be Mon Sep 17 00:00:00 2001 From: Adrian Hangan Date: Fri, 3 Mar 2017 16:00:36 +0200 Subject: [PATCH 2/2] bug fix --- demo/demo-custom-objects-as-options.html | 4 ++-- demo/index.html | 8 ++++---- etools-searchable-multiselection-menu.html | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/demo/demo-custom-objects-as-options.html b/demo/demo-custom-objects-as-options.html index 5caba65..60cebde 100644 --- a/demo/demo-custom-objects-as-options.html +++ b/demo/demo-custom-objects-as-options.html @@ -26,7 +26,7 @@

Multiple selection, custom objects as options

Custom objects as options and selected property with no change events

- + update-selected dynamic-align empty-value style="width: 350px;">

SelectedIDs: [[_returnIdsString(selectedIds)]]

etools-searchable-multiselection-menu demo

- +

Custom objects as options. You can specify value and label properties from object option to be used.

@@ -141,13 +141,13 @@

Custom objects as options. You can specify value and label properties from o - + diff --git a/etools-searchable-multiselection-menu.html b/etools-searchable-multiselection-menu.html index 1909749..d0b369b 100644 --- a/etools-searchable-multiselection-menu.html +++ b/etools-searchable-multiselection-menu.html @@ -744,11 +744,11 @@ } var selectedVals = null; - if (this.multi && Array.isArray(selectedValues)) { + if (this.multi) { // multiselection // selected will be empty array if selectedValues.length === 0 selectedVals = []; - if (selectedValues.length > 0) { + if (Array.isArray(selectedValues) && selectedValues.length > 0) { selectedVals = selectedValues.map(function(s) { return this._prepareValue(s); }.bind(this));