File tree Expand file tree Collapse file tree 2 files changed +101
-2
lines changed Expand file tree Collapse file tree 2 files changed +101
-2
lines changed Original file line number Diff line number Diff line change
1
+ import baseField from './baseField' ;
2
+ export default {
3
+ mixins : [ baseField ] ,
4
+ render ( h ) {
5
+ const children = [ ] ;
6
+ const self = this ;
7
+
8
+ // add the label if it needs it
9
+ if ( this . to . label ) children . push (
10
+ h ( 'label' , {
11
+ attrs : {
12
+ 'for' : this . to . id
13
+ }
14
+ } , this . to . label )
15
+ ) ;
16
+
17
+ // create each option
18
+ const options = [ ] ;
19
+ if ( 'options' in this . field ) {
20
+ this . field . options . forEach ( option => {
21
+ const optionVal = option . hasOwnProperty ( 'value' ) ? option . value : option ;
22
+ options . push (
23
+ h ( 'option' , {
24
+ domProps : {
25
+ value : optionVal
26
+ }
27
+ } , option . label || option )
28
+ ) ;
29
+ } ) ;
30
+ }
31
+
32
+ // add the element
33
+ children . push (
34
+ h ( 'select' , {
35
+ attrs : {
36
+ id : this . to . id ,
37
+ ...this . to . atts
38
+ } ,
39
+ 'class' : {
40
+ 'form-control' : true ,
41
+ ...this . to . classes
42
+ } ,
43
+ domProps : {
44
+ value : this . model [ this . field . key ]
45
+ } ,
46
+ on : {
47
+ click : this . onClick ,
48
+ blur : this . onBlur ,
49
+ focus : this . onFocus ,
50
+ keyup : this . onKeyup ,
51
+ keydown : this . onKeydown ,
52
+ change ( event ) {
53
+ self . model [ self . field . key ] = event . target . value ;
54
+ self . $emit ( 'change' , event . target . value ) ;
55
+ if ( typeof self . onChange === 'function' ) self . onChange ( event ) ;
56
+ }
57
+ }
58
+ } , options )
59
+ ) ;
60
+
61
+ // add the error element
62
+ children . push (
63
+ h ( 'error-display' , {
64
+ props : {
65
+ form : this . form ,
66
+ field : this . field . key
67
+ }
68
+ } )
69
+ ) ;
70
+
71
+ // create the wrapper element
72
+ return h ( 'div' , {
73
+ 'class' : [
74
+ 'form-group formly-select' ,
75
+ this . to . wrapperClasses ,
76
+ {
77
+ 'has-error has-danger' : this . hasError
78
+ }
79
+ ]
80
+ } , children ) ;
81
+ }
82
+ }
Original file line number Diff line number Diff line change @@ -300,8 +300,6 @@ describe('Bootstrap Field Inputs', () => {
300
300
} ) ;
301
301
302
302
} ) ;
303
-
304
- return ;
305
303
306
304
describe ( 'Select' , ( ) => {
307
305
describe ( 'functions' , ( ) => {
@@ -348,9 +346,28 @@ describe('Bootstrap Field Inputs', () => {
348
346
expect ( option . value ) . to . equal ( 'bar' ) ;
349
347
expect ( option . innerHTML ) . to . equal ( 'Foo' ) ;
350
348
} ) ;
349
+
350
+ it ( 'boolean options' , done => {
351
+ data . model . test = false ;
352
+ data . fields [ 0 ] . type = 'select' ;
353
+ data . fields [ 0 ] . options = [
354
+ { label : 'Foo' , value : true } ,
355
+ { label : 'Foo' , value : false }
356
+ ] ;
357
+ createForm ( ) ;
358
+ const select = vm . $el . querySelectorAll ( 'select' ) ;
359
+ expect ( select [ 0 ] . selectedIndex ) . to . equal ( 1 ) ;
360
+ vm . model . test = true ;
361
+ setTimeout ( ( ) => {
362
+ expect ( select [ 0 ] . selectedIndex ) . to . equal ( 0 ) ;
363
+ done ( ) ;
364
+ } ) ;
365
+ } ) ;
351
366
352
367
} ) ;
353
368
369
+ return ;
370
+
354
371
describe ( 'Textarea' , ( ) => {
355
372
describe ( 'functions' , ( ) => {
356
373
describeFunctions ( 'textarea' , 'textarea' ) ;
You can’t perform that action at this time.
0 commit comments