Merge pull request #5690 from tsiegleauq/search-value-single-val

Fix non-multipl os-search-val-selector
This commit is contained in:
Emanuel Schütze 2020-11-11 20:54:36 +01:00 committed by GitHub
commit 34070843c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -6,7 +6,7 @@
(openedChange)="openSelect($event)"
>
<!-- Custom display of selected items -->
<mat-select-trigger>
<mat-select-trigger *ngIf="multiple">
<ng-container *ngIf="selectedItems?.length">
<span *ngFor="let item of selectedItems; let i = index">
{{ item.getTitle() | translate }}<span *ngIf="i < selectedItems.length - 1">, </span>

View File

@ -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);
}