@@ -2037,7 +2037,8 @@ describe('IgxSimpleCombo', () => {
20372037 ReactiveFormsModule ,
20382038 FormsModule ,
20392039 IgxComboRemoteDataComponent ,
2040- IgxSimpleComboBindingDataAfterInitComponent
2040+ IgxSimpleComboBindingDataAfterInitComponent ,
2041+ IgxComboRemoteDataInReactiveFormComponent
20412042 ]
20422043 } ) . compileComponents ( ) ;
20432044 } ) ) ;
@@ -2129,6 +2130,37 @@ describe('IgxSimpleCombo', () => {
21292130
21302131 expect ( combo . comboInput . value ) . toEqual ( '' ) ;
21312132 } ) ;
2133+
2134+ it ( 'should display correct value after the value has been changed from the form and then by the user' , fakeAsync ( ( ) => {
2135+ fixture = TestBed . createComponent ( IgxComboRemoteDataInReactiveFormComponent ) ;
2136+ fixture . detectChanges ( ) ;
2137+ combo = fixture . componentInstance . reactiveCombo ;
2138+ const reactiveForm = fixture . componentInstance . reactiveForm ;
2139+ const reactiveControl = reactiveForm . form . controls [ 'comboValue' ] ;
2140+ input = fixture . debugElement . query ( By . css ( `.${ CSS_CLASS_COMBO_INPUTGROUP } ` ) ) ;
2141+ tick ( )
2142+ fixture . detectChanges ( ) ;
2143+ expect ( combo ) . toBeTruthy ( ) ;
2144+
2145+ combo . select ( 0 ) ;
2146+ fixture . detectChanges ( ) ;
2147+ expect ( combo . value ) . toEqual ( [ 0 ] ) ;
2148+ expect ( input . nativeElement . value ) . toEqual ( 'Product 0' ) ;
2149+
2150+ reactiveControl . setValue ( 3 ) ;
2151+ fixture . detectChanges ( ) ;
2152+ expect ( combo . value ) . toEqual ( [ 3 ] ) ;
2153+ expect ( input . nativeElement . value ) . toEqual ( 'Product 3' ) ;
2154+
2155+ combo . open ( ) ;
2156+ fixture . detectChanges ( ) ;
2157+ const item1 = fixture . debugElement . queryAll ( By . css ( `.${ CSS_CLASS_DROPDOWNLISTITEM } ` ) ) [ 5 ] ;
2158+ item1 . triggerEventHandler ( 'click' , UIInteractions . getMouseEvent ( 'click' ) ) ;
2159+ fixture . detectChanges ( ) ;
2160+
2161+ expect ( combo . value ) . toEqual ( [ 5 ] ) ;
2162+ expect ( input . nativeElement . value ) . toEqual ( 'Product 5' ) ;
2163+ } ) ) ;
21322164 } ) ;
21332165} ) ;
21342166
@@ -2378,6 +2410,59 @@ class IgxSimpleComboInTemplatedFormComponent {
23782410 }
23792411}
23802412
2413+ @Component ( {
2414+ providers : [ RemoteDataService ] ,
2415+ template : `
2416+ <form [formGroup]="comboForm" #reactiveForm="ngForm">
2417+ <igx-simple-combo #reactiveCombo [placeholder]="'Products'" [data]="data | async" (dataPreLoad)="dataLoading($event)" [itemsMaxHeight]='400'
2418+ [itemHeight]='40' [valueKey]="'id'" [displayKey]="'product'" [width]="'400px'" formControlName="comboValue" name="combo">
2419+ </igx-simple-combo>
2420+ <button #button IgxButton (click)="changeValue()">Change value</button>
2421+ </form>
2422+ ` ,
2423+ standalone : true ,
2424+ imports : [ IgxSimpleComboComponent , AsyncPipe , ReactiveFormsModule ]
2425+ } )
2426+ export class IgxComboRemoteDataInReactiveFormComponent implements OnInit , AfterViewInit , OnDestroy {
2427+ @ViewChild ( 'reactiveCombo' , { read : IgxSimpleComboComponent , static : true } )
2428+ public reactiveCombo : IgxSimpleComboComponent ;
2429+ @ViewChild ( 'button' , { read : HTMLButtonElement , static : true } )
2430+ public button : HTMLButtonElement ;
2431+ @ViewChild ( 'reactiveForm' )
2432+ public reactiveForm : NgForm ;
2433+ public comboForm : UntypedFormGroup ;
2434+ public data ;
2435+ constructor ( private remoteDataService : RemoteDataService , public cdr : ChangeDetectorRef , fb : UntypedFormBuilder ) {
2436+ this . comboForm = fb . group ( {
2437+ comboValue : new UntypedFormControl ( '' , Validators . required ) ,
2438+ } ) ;
2439+ }
2440+ public ngOnInit ( ) : void {
2441+ this . data = this . remoteDataService . records ;
2442+ }
2443+
2444+ public ngAfterViewInit ( ) {
2445+ this . remoteDataService . getData ( this . reactiveCombo . virtualizationState , ( count ) => {
2446+ this . reactiveCombo . totalItemCount = count ;
2447+ this . cdr . detectChanges ( ) ;
2448+ } ) ;
2449+ }
2450+
2451+ public dataLoading ( evt ) {
2452+ this . remoteDataService . getData ( evt , ( ) => {
2453+ this . cdr . detectChanges ( ) ;
2454+ } ) ;
2455+ }
2456+
2457+ public ngOnDestroy ( ) {
2458+ this . cdr . detach ( ) ;
2459+ }
2460+
2461+ public changeValue ( ) {
2462+ this . comboForm . get ( 'comboValue' ) . setValue ( 14 ) ;
2463+ }
2464+ }
2465+
23812466@Component ( {
23822467 template : `
23832468 <form [formGroup]="comboForm" #reactiveForm="ngForm">
0 commit comments