From 85694ec285401903a8d51fd533e2221bf0e467a0 Mon Sep 17 00:00:00 2001 From: Jens Vannerum Date: Wed, 14 Feb 2024 10:41:24 +0100 Subject: [PATCH 1/2] 111768: add back necessary setCurrentValue calls that were removed earlier --- .../dynamic-scrollable-dropdown.component.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.ts index 5e0538a1715..3142d1787f5 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.ts @@ -11,7 +11,7 @@ import { import { UntypedFormGroup } from '@angular/forms'; import { Observable, of as observableOf } from 'rxjs'; -import { catchError, map, tap } from 'rxjs/operators'; +import { catchError, distinctUntilChanged, map, tap } from 'rxjs/operators'; import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap'; import { DynamicFormLayoutService, DynamicFormValidationService } from '@ng-dynamic-forms/core'; @@ -79,6 +79,10 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom tap(() => this.loading = false) ).subscribe((list: PaginatedList) => { this.optionsList = list.page; + if (this.model.value) { + this.setCurrentValue(this.model.value, true); + } + this.updatePageInfo( list.pageInfo.elementsPerPage, list.pageInfo.currentPage, @@ -88,6 +92,11 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom this.selectedIndex = 0; this.cdr.detectChanges(); }); + + this.group.get(this.model.id).valueChanges.pipe(distinctUntilChanged()) + .subscribe((value) => { + this.setCurrentValue(value); + }); } /** From d920567f8a2ba9aabeabb56f1863548dc1d9ce04 Mon Sep 17 00:00:00 2001 From: Jens Vannerum Date: Mon, 19 Feb 2024 11:42:57 +0100 Subject: [PATCH 2/2] 111768: move original code back to init only for performance --- .../dynamic-scrollable-dropdown.component.ts | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.ts index 3142d1787f5..c902807cd43 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.ts @@ -68,10 +68,14 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom */ ngOnInit() { this.updatePageInfo(this.model.maxOptions, 1); - this.loadOptions(); + this.loadOptions(true); + this.group.get(this.model.id).valueChanges.pipe(distinctUntilChanged()) + .subscribe((value) => { + this.setCurrentValue(value); + }); } - loadOptions() { + loadOptions(fromInit: boolean) { this.loading = true; this.vocabularyService.getVocabularyEntriesByValue(this.inputText, false, this.model.vocabularyOptions, this.pageInfo).pipe( getFirstSucceededRemoteDataPayload(), @@ -79,7 +83,7 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom tap(() => this.loading = false) ).subscribe((list: PaginatedList) => { this.optionsList = list.page; - if (this.model.value) { + if (fromInit && this.model.value) { this.setCurrentValue(this.model.value, true); } @@ -92,11 +96,6 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom this.selectedIndex = 0; this.cdr.detectChanges(); }); - - this.group.get(this.model.id).valueChanges.pipe(distinctUntilChanged()) - .subscribe((value) => { - this.setCurrentValue(value); - }); } /** @@ -113,7 +112,7 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom this.group.markAsUntouched(); this.inputText = null; this.updatePageInfo(this.model.maxOptions, 1); - this.loadOptions(); + this.loadOptions(false); sdRef.open(); } } @@ -170,7 +169,7 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom this.inputText += keyName; // When a new key is added, we need to reset the page info this.updatePageInfo(this.model.maxOptions, 1); - this.loadOptions(); + this.loadOptions(false); } removeKeyFromInput() { @@ -179,7 +178,7 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom if (this.inputText === '') { this.inputText = null; } - this.loadOptions(); + this.loadOptions(false); } }