@@ -33,7 +33,7 @@ function trigger (target, event, process) {
33
33
function describeFunctions ( formlyElement , inputElement , inputType = 'text' , options ) {
34
34
beforeEach ( ( ) => {
35
35
data . fields [ 0 ] . type = formlyElement ;
36
- data . fields [ 0 ] . templateOptions . type = inputType ;
36
+ data . fields [ 0 ] . templateOptions . inputType = inputType ;
37
37
if ( typeof options != 'undefined' ) data . fields [ 0 ] . options = options ;
38
38
spy = sinon . spy ( ) ;
39
39
} ) ;
@@ -103,7 +103,7 @@ function describeFunctions(formlyElement, inputElement, inputType = 'text', opti
103
103
function describeAttributes ( inputElement , testPlaceholder = true ) {
104
104
beforeEach ( ( ) => {
105
105
data . fields [ 0 ] . type = inputElement ;
106
- data . fields [ 0 ] . templateOptions . type = 'text' ;
106
+ data . fields [ 0 ] . templateOptions . inputType = 'text' ;
107
107
} ) ;
108
108
109
109
it ( 'attributes' , ( ) => {
@@ -142,7 +142,7 @@ function describeAttributes(inputElement, testPlaceholder = true){
142
142
function describeConditional ( inputElement ) {
143
143
it ( 'label' , ( done ) => {
144
144
data . fields [ 0 ] . type = inputElement ;
145
- data . fields [ 0 ] . templateOptions . type = 'text' ;
145
+ data . fields [ 0 ] . templateOptions . inputType = 'text' ;
146
146
data . fields [ 0 ] . templateOptions . label = '' ;
147
147
createForm ( data ) ;
148
148
@@ -177,6 +177,22 @@ describe('Bootstrap Field Inputs', () => {
177
177
} ;
178
178
} ) ;
179
179
180
+ describe ( 'Errors' , ( ) => {
181
+ it ( 'should receive an error state' , ( ) => {
182
+ data . fields [ 0 ] . type = 'input' ;
183
+ data . fields [ 0 ] . required = true ;
184
+ createForm ( ) ;
185
+
186
+ expect ( data . form [ 'test' ] . $hasError ) . to . be . false ;
187
+ trigger ( vm . $el . querySelectorAll ( 'input' ) [ 0 ] , 'focus' ) ;
188
+ expect ( data . form [ 'test' ] . $hasError ) . to . be . false ;
189
+ expect ( data . form [ 'test' ] . $active ) . to . be . true ;
190
+
191
+ trigger ( vm . $el . querySelectorAll ( 'input' ) [ 0 ] , 'change' ) ;
192
+ expect ( data . form [ 'test' ] . $hasError ) . to . be . false ;
193
+ } ) ;
194
+ } ) ;
195
+
180
196
describe ( 'Input' , ( ) => {
181
197
182
198
describe ( 'functions' , ( ) => {
@@ -187,7 +203,7 @@ describe('Bootstrap Field Inputs', () => {
187
203
describeAttributes ( 'input' ) ;
188
204
it ( 'should have input type as a class' , ( ) => {
189
205
data . fields [ 0 ] . type = 'input' ;
190
- data . fields [ 0 ] . templateOptions . type = 'text' ;
206
+ data . fields [ 0 ] . templateOptions . inputType = 'text' ;
191
207
createForm ( data ) ;
192
208
193
209
let els = vm . $el . querySelectorAll ( '.text' ) ;
@@ -203,7 +219,7 @@ describe('Bootstrap Field Inputs', () => {
203
219
204
220
it ( 'layout' , ( done ) => {
205
221
data . fields [ 0 ] . type = 'input' ;
206
- data . fields [ 0 ] . templateOptions . type = 'text' ;
222
+ data . fields [ 0 ] . templateOptions . inputType = 'text' ;
207
223
createForm ( data ) ;
208
224
209
225
let inputs = vm . $el . querySelectorAll ( 'input' ) ;
@@ -226,7 +242,7 @@ describe('Bootstrap Field Inputs', () => {
226
242
227
243
it ( 'adds active and focus classes' , ( done ) => {
228
244
data . fields [ 0 ] . type = 'input' ;
229
- data . fields [ 0 ] . templateOptions . type = 'text' ;
245
+ data . fields [ 0 ] . templateOptions . inputType = 'text' ;
230
246
createForm ( data ) ;
231
247
232
248
expect ( vm . $el . querySelectorAll ( '.formly-has-focus' ) ) . to . be . length ( 0 ) ;
@@ -243,7 +259,7 @@ describe('Bootstrap Field Inputs', () => {
243
259
244
260
it ( 'defaults to text' , ( ) => {
245
261
data . fields [ 0 ] . type = 'input' ;
246
- data . fields [ 0 ] . templateOptions . type = undefined ;
262
+ data . fields [ 0 ] . templateOptions . inputType = undefined ;
247
263
createForm ( data ) ;
248
264
249
265
let inputs = vm . $el . querySelectorAll ( 'input' ) ;
@@ -363,7 +379,7 @@ describe('Bootstrap Field Inputs', () => {
363
379
364
380
it ( 'array options' , ( ) => {
365
381
data . fields [ 0 ] . type = 'list' ;
366
- data . fields [ 0 ] . templateOptions . type = 'checkbox' ;
382
+ data . fields [ 0 ] . templateOptions . inputType = 'checkbox' ;
367
383
data . fields [ 0 ] . options = [ 'one' , 'two' , 'three' ] ;
368
384
createForm ( ) ;
369
385
@@ -378,7 +394,7 @@ describe('Bootstrap Field Inputs', () => {
378
394
379
395
it ( 'object options' , ( ) => {
380
396
data . fields [ 0 ] . type = 'list' ;
381
- data . fields [ 0 ] . templateOptions . type = 'checkbox'
397
+ data . fields [ 0 ] . templateOptions . inputType = 'checkbox'
382
398
data . fields [ 0 ] . options = [
383
399
{ label : 'Foo' , value : 'bar' } ,
384
400
{ label : 'Bar' , value : 'foo' }
@@ -418,7 +434,7 @@ describe('Bootstrap Field Inputs', () => {
418
434
419
435
it ( 'multiple values' , ( done ) => {
420
436
data . fields [ 0 ] . type = 'list' ;
421
- data . fields [ 0 ] . templateOptions . type = 'checkbox' ;
437
+ data . fields [ 0 ] . templateOptions . inputType = 'checkbox' ;
422
438
data . fields [ 0 ] . options = [ 'one' , 'two' ] ;
423
439
createForm ( ) ;
424
440
@@ -433,7 +449,7 @@ describe('Bootstrap Field Inputs', () => {
433
449
434
450
it ( 'single value' , ( done ) => {
435
451
data . fields [ 0 ] . type = 'list' ;
436
- data . fields [ 0 ] . templateOptions . type = 'radio' ;
452
+ data . fields [ 0 ] . templateOptions . inputType = 'radio' ;
437
453
data . fields [ 0 ] . options = [ 'one' , 'two' ] ;
438
454
createForm ( ) ;
439
455
@@ -445,6 +461,28 @@ describe('Bootstrap Field Inputs', () => {
445
461
done ( ) ;
446
462
} , 0 ) ;
447
463
} ) ;
464
+
465
+ it ( 'only shows a checkbox' , ( ) => {
466
+ data . fields [ 0 ] . type = 'list' ;
467
+ data . fields [ 0 ] . options = [ 'one' , 'two' ] ;
468
+ createForm ( ) ;
469
+ let inputs = vm . $el . querySelectorAll ( 'input' ) ;
470
+ expect ( inputs ) . to . be . length ( 2 ) ;
471
+ expect ( inputs [ 0 ] . type ) . to . equal ( 'checkbox' ) ;
472
+ expect ( inputs [ 1 ] . type ) . to . equal ( 'checkbox' ) ;
473
+ } ) ;
474
+
475
+ it ( 'only shows a radio box' , ( ) => {
476
+ data . fields [ 0 ] . type = 'list' ;
477
+ data . fields [ 0 ] . templateOptions . inputType = 'radio' ;
478
+ data . fields [ 0 ] . options = [ 'one' , 'two' ] ;
479
+ createForm ( ) ;
480
+ let inputs = vm . $el . querySelectorAll ( 'input' ) ;
481
+ expect ( inputs ) . to . be . length ( 2 ) ;
482
+ expect ( inputs [ 0 ] . type ) . to . equal ( 'radio' ) ;
483
+ expect ( inputs [ 1 ] . type ) . to . equal ( 'radio' ) ;
484
+ } ) ;
485
+
448
486
} ) ;
449
487
450
488
} ) ;
0 commit comments