From ad16259d2391e5a5fecb58830c6f5891d890c556 Mon Sep 17 00:00:00 2001 From: ghiscoding Date: Tue, 23 Feb 2021 08:42:20 -0500 Subject: [PATCH] fix(filters): make sure Select Editor/Filter collection is filled - add an extra collection length check before rendering the Select Editor/Filter dropdown to avoid multiple-select.js throwing errors that it can't find list or items --- src/app/modules/angular-slickgrid/editors/selectEditor.ts | 7 +++++-- src/app/modules/angular-slickgrid/filters/selectFilter.ts | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/app/modules/angular-slickgrid/editors/selectEditor.ts b/src/app/modules/angular-slickgrid/editors/selectEditor.ts index 77ff49414..03de2eb36 100644 --- a/src/app/modules/angular-slickgrid/editors/selectEditor.ts +++ b/src/app/modules/angular-slickgrid/editors/selectEditor.ts @@ -443,10 +443,13 @@ export class SelectEditor implements Editor { } isValueChanged(): boolean { + const valueSelection = this.$editorElm.multipleSelect('getSelects'); if (this.isMultipleSelect) { - return !dequal(this.$editorElm.val(), this.originalValue); + const isEqual = dequal(valueSelection, this.originalValue); + return !isEqual; } - return this.$editorElm.val() !== this.originalValue; + const value = Array.isArray(valueSelection) && valueSelection.length > 0 ? valueSelection[0] : undefined; + return value !== this.originalValue; } validate(inputValue?: any): EditorValidatorOutput { diff --git a/src/app/modules/angular-slickgrid/filters/selectFilter.ts b/src/app/modules/angular-slickgrid/filters/selectFilter.ts index 8e0cdeb44..e0c490c99 100644 --- a/src/app/modules/angular-slickgrid/filters/selectFilter.ts +++ b/src/app/modules/angular-slickgrid/filters/selectFilter.ts @@ -28,6 +28,7 @@ import { castToPromise, getDescendantProperty, getTranslationPrefix, htmlEncode, declare const $: any; export class SelectFilter implements Filter { + protected _collectionLength = 0; protected _isMultipleSelect = true; protected _locales: Locale; protected _shouldTriggerQuery = true; @@ -168,7 +169,7 @@ export class SelectFilter implements Filter { * Clear the filter values */ clear(shouldTriggerQuery = true) { - if (this.$filterElm && this.$filterElm.multipleSelect) { + if (this.$filterElm && this.$filterElm.multipleSelect && this._collectionLength > 0) { // reload the filter element by it's id, to make sure it's still a valid element (because of some issue in the GraphQL example) this.$filterElm.multipleSelect('setSelects', []); this.$filterElm.removeClass('filled'); @@ -352,6 +353,7 @@ export class SelectFilter implements Filter { // step 2, create the DOM Element of the filter & pre-load search terms // also subscribe to the onClose event this.createDomElement(filterTemplate); + this._collectionLength = newCollection.length; } /** Create the HTML template as a string */