@@ -5,7 +5,7 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
5
5
import { SortingDirection } from '../data-operations/sorting-expression.interface' ;
6
6
import { IgxToggleModule } from '../directives/toggle/toggle.directive' ;
7
7
import { IgxComboItemComponent } from './combo-item.component' ;
8
- import { IgxComboComponent , IgxComboModule , IgxComboState , IComboSelectionChangeEventArgs } from './combo.component' ;
8
+ import { IgxComboComponent , IgxComboModule , IComboSelectionChangeEventArgs , IgxComboState } from './combo.component' ;
9
9
import { IgxComboDropDownComponent } from './combo-dropdown.component' ;
10
10
import { FormGroup , FormControl , Validators , FormBuilder , ReactiveFormsModule , FormsModule } from '@angular/forms' ;
11
11
import { IForOfState } from '../directives/for-of/for_of.directive' ;
@@ -17,6 +17,7 @@ import { configureTestSuite } from '../test-utils/configure-suite';
17
17
import { IgxDropDownItemBase } from '../drop-down/drop-down-item.base' ;
18
18
import { DisplayDensity , DisplayDensityToken } from '../core/density' ;
19
19
import { AbsoluteScrollStrategy , ConnectedPositioningStrategy } from '../services/index' ;
20
+ import { IgxInputState } from '../directives/input/input.directive' ;
20
21
21
22
const CSS_CLASS_COMBO = 'igx-combo' ;
22
23
const CSS_CLASS_COMBO_DROPDOWN = 'igx-combo__drop-down' ;
@@ -40,6 +41,7 @@ const CSS_CLASS_INPUTGROUP = 'igx-input-group';
40
41
const CSS_CLASS_INPUTGROUP_WRAPPER = 'igx-input-group__wrapper' ;
41
42
const CSS_CLASS_INPUTGROUP_BUNDLE = 'igx-input-group__bundle' ;
42
43
const CSS_CLASS_INPUTGROUP_MAINBUNDLE = 'igx-input-group__bundle-main' ;
44
+ const CSS_CLASS_INPUTGROUP_REQUIRED = 'igx-input-group--required' ;
43
45
const CSS_CLASS_INPUTGROUP_BORDER = 'igx-input-group__border' ;
44
46
const CSS_CLASS_HEADER = 'header-class' ;
45
47
const CSS_CLASS_FOOTER = 'footer-class' ;
@@ -76,7 +78,8 @@ describe('igxCombo', () => {
76
78
IgxComboFormComponent ,
77
79
SimpleBindComboComponent ,
78
80
DensityParentComponent ,
79
- DensityInputComponent
81
+ DensityInputComponent ,
82
+ IgxComboInTemplatedFormComponent
80
83
] ,
81
84
imports : [
82
85
IgxComboModule ,
@@ -3048,7 +3051,6 @@ describe('igxCombo', () => {
3048
3051
} ) ;
3049
3052
3050
3053
describe ( 'Form control tests: ' , ( ) => {
3051
-
3052
3054
it ( 'Should properly initialize when used as a form control' , fakeAsync ( ( ) => {
3053
3055
const fix = TestBed . createComponent ( IgxComboFormComponent ) ;
3054
3056
fix . detectChanges ( ) ;
@@ -3060,21 +3062,26 @@ describe('igxCombo', () => {
3060
3062
expect ( combo . selectedItems ( ) . length ) . toEqual ( 1 ) ;
3061
3063
expect ( combo . selectedItems ( ) [ 0 ] . field ) . toEqual ( 'Connecticut' ) ;
3062
3064
expect ( combo . valid ) . toEqual ( IgxComboState . INITIAL ) ;
3065
+ expect ( combo . comboInput . valid ) . toEqual ( IgxInputState . INITIAL ) ;
3063
3066
const clearButton = fix . debugElement . query ( By . css ( '.' + CSS_CLASS_CLEARBUTTON ) ) . nativeElement ;
3064
3067
clearButton . click ( ) ;
3065
3068
fix . detectChanges ( ) ;
3066
3069
expect ( combo . valid ) . toEqual ( IgxComboState . INVALID ) ;
3070
+ expect ( combo . comboInput . valid ) . toEqual ( IgxInputState . INVALID ) ;
3067
3071
3068
3072
combo . onBlur ( ) ;
3069
3073
fix . detectChanges ( ) ;
3070
3074
expect ( combo . valid ) . toEqual ( IgxComboState . INVALID ) ;
3075
+ expect ( combo . comboInput . valid ) . toEqual ( IgxInputState . INVALID ) ;
3071
3076
3072
3077
combo . selectItems ( [ combo . dropdown . items [ 0 ] , combo . dropdown . items [ 1 ] ] ) ;
3073
3078
expect ( combo . valid ) . toEqual ( IgxComboState . VALID ) ;
3079
+ expect ( combo . comboInput . valid ) . toEqual ( IgxInputState . VALID ) ;
3074
3080
3075
3081
combo . onBlur ( ) ;
3076
3082
fix . detectChanges ( ) ;
3077
3083
expect ( combo . valid ) . toEqual ( IgxComboState . INITIAL ) ;
3084
+ expect ( combo . comboInput . valid ) . toEqual ( IgxInputState . INITIAL ) ;
3078
3085
} ) ) ;
3079
3086
3080
3087
it ( 'Should properly initialize when used as a form control - without validators' , fakeAsync ( ( ) => {
@@ -3090,21 +3097,26 @@ describe('igxCombo', () => {
3090
3097
expect ( combo . selectedItems ( ) . length ) . toEqual ( 1 ) ;
3091
3098
expect ( combo . selectedItems ( ) [ 0 ] . field ) . toEqual ( 'Connecticut' ) ;
3092
3099
expect ( combo . valid ) . toEqual ( IgxComboState . INITIAL ) ;
3100
+ expect ( combo . comboInput . valid ) . toEqual ( IgxInputState . INITIAL ) ;
3093
3101
const clearButton = fix . debugElement . query ( By . css ( '.' + CSS_CLASS_CLEARBUTTON ) ) . nativeElement ;
3094
3102
clearButton . click ( ) ;
3095
3103
fix . detectChanges ( ) ;
3096
3104
expect ( combo . valid ) . toEqual ( IgxComboState . INITIAL ) ;
3105
+ expect ( combo . comboInput . valid ) . toEqual ( IgxInputState . INITIAL ) ;
3097
3106
3098
3107
combo . onBlur ( ) ;
3099
3108
fix . detectChanges ( ) ;
3100
3109
expect ( combo . valid ) . toEqual ( IgxComboState . INITIAL ) ;
3110
+ expect ( combo . comboInput . valid ) . toEqual ( IgxInputState . INITIAL ) ;
3101
3111
3102
3112
combo . selectItems ( [ combo . dropdown . items [ 0 ] , combo . dropdown . items [ 1 ] ] ) ;
3103
3113
expect ( combo . valid ) . toEqual ( IgxComboState . INITIAL ) ;
3114
+ expect ( combo . comboInput . valid ) . toEqual ( IgxInputState . INITIAL ) ;
3104
3115
3105
3116
combo . onBlur ( ) ;
3106
3117
fix . detectChanges ( ) ;
3107
3118
expect ( combo . valid ) . toEqual ( IgxComboState . INITIAL ) ;
3119
+ expect ( combo . comboInput . valid ) . toEqual ( IgxInputState . INITIAL ) ;
3108
3120
} ) ) ;
3109
3121
3110
3122
it ( 'Should be possible to be enabled/disabled when used as a form control' , ( ) => {
@@ -3196,6 +3208,36 @@ describe('igxCombo', () => {
3196
3208
fixture . detectChanges ( ) ;
3197
3209
expect ( fixture . componentInstance . comboSelectedItems ) . toEqual ( [ ...data ] . splice ( 1 , 3 ) ) ;
3198
3210
} ) ) ;
3211
+
3212
+ it ( 'Should properly initialize when used in a Template form control' , fakeAsync ( ( ) => {
3213
+ const fix = TestBed . createComponent ( IgxComboInTemplatedFormComponent ) ;
3214
+ fix . detectChanges ( ) ;
3215
+ tick ( ) ;
3216
+
3217
+ const combo = fix . componentInstance . testCombo ;
3218
+ expect ( combo . valid ) . toEqual ( IgxComboState . INITIAL ) ;
3219
+ expect ( combo . comboInput . valid ) . toEqual ( IgxInputState . INITIAL ) ;
3220
+ const inputGroupRequired = fix . debugElement . query ( By . css ( '.' + CSS_CLASS_INPUTGROUP_REQUIRED ) ) ;
3221
+ expect ( inputGroupRequired ) . toBeDefined ( ) ;
3222
+ combo . onBlur ( ) ;
3223
+ fix . detectChanges ( ) ;
3224
+ tick ( ) ;
3225
+ expect ( combo . valid ) . toEqual ( IgxComboState . INVALID ) ;
3226
+ expect ( combo . comboInput . valid ) . toEqual ( IgxInputState . INVALID ) ;
3227
+
3228
+ combo . selectAllItems ( ) ;
3229
+ fix . detectChanges ( ) ;
3230
+ tick ( ) ;
3231
+ expect ( combo . valid ) . toEqual ( IgxComboState . VALID ) ;
3232
+ expect ( combo . comboInput . valid ) . toEqual ( IgxInputState . VALID ) ;
3233
+
3234
+ const clearButton = fix . debugElement . query ( By . css ( '.' + CSS_CLASS_CLEARBUTTON ) ) . nativeElement ;
3235
+ clearButton . click ( ) ;
3236
+ fix . detectChanges ( ) ;
3237
+ tick ( ) ;
3238
+ expect ( combo . valid ) . toEqual ( IgxComboState . INVALID ) ;
3239
+ expect ( combo . comboInput . valid ) . toEqual ( IgxInputState . INVALID ) ;
3240
+ } ) ) ;
3199
3241
} ) ;
3200
3242
3201
3243
describe ( 'Combo - Display Density' , ( ) => {
@@ -3553,6 +3595,54 @@ class IgxComboFormComponent {
3553
3595
onSubmitTemplateBased ( ) { }
3554
3596
}
3555
3597
3598
+ @Component ( {
3599
+ template : `
3600
+ <form>
3601
+ <igx-combo #testCombo class="input-container" [placeholder]="'Locations'"
3602
+ name="anyName" required [(ngModel)]="values"
3603
+ [data]="items" [filterable]="filterableFlag"
3604
+ [displayKey]="'field'" [valueKey]="'field'"
3605
+ [groupKey]="'field' ? 'region' : ''" [width]="'100%'">
3606
+ <label igxLabel>Combo Label</label>
3607
+ </igx-combo>
3608
+ </form>
3609
+ `
3610
+ } )
3611
+ class IgxComboInTemplatedFormComponent {
3612
+ @ViewChild ( 'testCombo' , { read : IgxComboComponent , static : true } ) testCombo : IgxComboComponent ;
3613
+ public items : any [ ] = [ ] ;
3614
+ public values : Array < any > ;
3615
+
3616
+ constructor ( ) {
3617
+ const division = {
3618
+ 'New England 01' : [ 'Connecticut' , 'Maine' , 'Massachusetts' ] ,
3619
+ 'New England 02' : [ 'New Hampshire' , 'Rhode Island' , 'Vermont' ] ,
3620
+ 'Mid-Atlantic' : [ 'New Jersey' , 'New York' , 'Pennsylvania' ] ,
3621
+ 'East North Central 02' : [ 'Michigan' , 'Ohio' , 'Wisconsin' ] ,
3622
+ 'East North Central 01' : [ 'Illinois' , 'Indiana' ] ,
3623
+ 'West North Central 01' : [ 'Missouri' , 'Nebraska' , 'North Dakota' , 'South Dakota' ] ,
3624
+ 'West North Central 02' : [ 'Iowa' , 'Kansas' , 'Minnesota' ] ,
3625
+ 'South Atlantic 01' : [ 'Delaware' , 'Florida' , 'Georgia' , 'Maryland' ] ,
3626
+ 'South Atlantic 02' : [ 'North Carolina' , 'South Carolina' , 'Virginia' ] ,
3627
+ 'South Atlantic 03' : [ 'District of Columbia' , 'West Virginia' ] ,
3628
+ 'East South Central 01' : [ 'Alabama' , 'Kentucky' ] ,
3629
+ 'East South Central 02' : [ 'Mississippi' , 'Tennessee' ] ,
3630
+ 'West South Central' : [ 'Arkansas' , 'Louisiana' , 'Oklahome' , 'Texas' ] ,
3631
+ 'Mountain' : [ 'Arizona' , 'Colorado' , 'Idaho' , 'Montana' , 'Nevada' , 'New Mexico' , 'Utah' , 'Wyoming' ] ,
3632
+ 'Pacific 01' : [ 'Alaska' , 'California' ] ,
3633
+ 'Pacific 02' : [ 'Hawaii' , 'Oregon' , 'Washington' ]
3634
+ } ;
3635
+ const keys = Object . keys ( division ) ;
3636
+ for ( const key of keys ) {
3637
+ division [ key ] . map ( ( e ) => {
3638
+ this . items . push ( {
3639
+ field : e ,
3640
+ region : key . substring ( 0 , key . length - 3 )
3641
+ } ) ;
3642
+ } ) ;
3643
+ }
3644
+ }
3645
+ }
3556
3646
@Injectable ( )
3557
3647
export class LocalService {
3558
3648
public getData ( ) {
0 commit comments