@@ -11,7 +11,7 @@ import {
1111import { UntypedFormGroup } from '@angular/forms' ;
1212
1313import { Observable , of as observableOf } from 'rxjs' ;
14- import { catchError , map , tap } from 'rxjs/operators' ;
14+ import { catchError , distinctUntilChanged , map , tap } from 'rxjs/operators' ;
1515import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap' ;
1616import { DynamicFormLayoutService , DynamicFormValidationService } from '@ng-dynamic-forms/core' ;
1717
@@ -68,17 +68,25 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom
6868 */
6969 ngOnInit ( ) {
7070 this . updatePageInfo ( this . model . maxOptions , 1 ) ;
71- this . loadOptions ( ) ;
71+ this . loadOptions ( true ) ;
72+ this . group . get ( this . model . id ) . valueChanges . pipe ( distinctUntilChanged ( ) )
73+ . subscribe ( ( value ) => {
74+ this . setCurrentValue ( value ) ;
75+ } ) ;
7276 }
7377
74- loadOptions ( ) {
78+ loadOptions ( fromInit : boolean ) {
7579 this . loading = true ;
7680 this . vocabularyService . getVocabularyEntriesByValue ( this . inputText , false , this . model . vocabularyOptions , this . pageInfo ) . pipe (
7781 getFirstSucceededRemoteDataPayload ( ) ,
7882 catchError ( ( ) => observableOf ( buildPaginatedList ( new PageInfo ( ) , [ ] ) ) ) ,
7983 tap ( ( ) => this . loading = false )
8084 ) . subscribe ( ( list : PaginatedList < VocabularyEntry > ) => {
8185 this . optionsList = list . page ;
86+ if ( fromInit && this . model . value ) {
87+ this . setCurrentValue ( this . model . value , true ) ;
88+ }
89+
8290 this . updatePageInfo (
8391 list . pageInfo . elementsPerPage ,
8492 list . pageInfo . currentPage ,
@@ -104,7 +112,7 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom
104112 this . group . markAsUntouched ( ) ;
105113 this . inputText = null ;
106114 this . updatePageInfo ( this . model . maxOptions , 1 ) ;
107- this . loadOptions ( ) ;
115+ this . loadOptions ( false ) ;
108116 sdRef . open ( ) ;
109117 }
110118 }
@@ -161,7 +169,7 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom
161169 this . inputText += keyName ;
162170 // When a new key is added, we need to reset the page info
163171 this . updatePageInfo ( this . model . maxOptions , 1 ) ;
164- this . loadOptions ( ) ;
172+ this . loadOptions ( false ) ;
165173 }
166174
167175 removeKeyFromInput ( ) {
@@ -170,7 +178,7 @@ export class DsDynamicScrollableDropdownComponent extends DsDynamicVocabularyCom
170178 if ( this . inputText === '' ) {
171179 this . inputText = null ;
172180 }
173- this . loadOptions ( ) ;
181+ this . loadOptions ( false ) ;
174182 }
175183 }
176184
0 commit comments