From a188abed486ed7a93369ccad6c8faa0d86272d48 Mon Sep 17 00:00:00 2001 From: Sean Date: Mon, 9 Nov 2020 15:33:58 +0100 Subject: [PATCH] Fix non-multipl os-search-val-selector Fixes a bug there non multiple uses of search value selector was submitting the value twice due to late alterations of internal form objects --- .../search-value-selector.component.html | 2 +- .../search-value-selector.component.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/client/src/app/shared/components/search-value-selector/search-value-selector.component.html b/client/src/app/shared/components/search-value-selector/search-value-selector.component.html index 7a8739f7b..4dcb653db 100644 --- a/client/src/app/shared/components/search-value-selector/search-value-selector.component.html +++ b/client/src/app/shared/components/search-value-selector/search-value-selector.component.html @@ -6,7 +6,7 @@ (openedChange)="openSelect($event)" > - + {{ item.getTitle() | translate }}, diff --git a/client/src/app/shared/components/search-value-selector/search-value-selector.component.ts b/client/src/app/shared/components/search-value-selector/search-value-selector.component.ts index 4ced18806..4de12f155 100644 --- a/client/src/app/shared/components/search-value-selector/search-value-selector.component.ts +++ b/client/src/app/shared/components/search-value-selector/search-value-selector.component.ts @@ -124,9 +124,12 @@ export class SearchValueSelectorComponent extends BaseFormControlComponentDirect } public get selectedItems(): Selectable[] { - return this.selectableItems && this.contentForm.value - ? this.selectableItems.filter(item => this.contentForm.value.includes(item.id)) - : []; + if (this.multiple && this.selectableItems?.length && this.contentForm.value) { + return this.selectableItems.filter(item => { + return this.contentForm.value.includes(item.id); + }); + } + return []; } public controlType = 'search-value-selector'; @@ -197,7 +200,7 @@ export class SearchValueSelectorComponent extends BaseFormControlComponentDirect } public onSelectionChange(change: MatOptionSelectionChange): void { - if (change.isUserInput) { + if (this.multiple && change.isUserInput) { const value = change.source.value; this.addRemoveId(value); }