@@ -18,11 +18,17 @@ block content
18
18
.col-sm-9
19
19
input.form-control ( type ="number" , value ="#{val .default } " , step ="any" , name ="#{key} " , id ="#{key} " , required )
20
20
else if (val .type === " bool" )
21
- // TODO Consider replacing with two radio buttons
22
21
.form-group.row
23
22
label.form-control-label.control-label.col-sm-3 ( for ="#{key} " ) #{key}
24
23
.col-sm-9
25
- input.form-control ( type ="text" , value ="#{val .default } " , pattern ="(true|false)" , title ="Enter true or false" , name ="#{key} " , id ="#{key} " , required )
24
+ .form-check.form-check-inline
25
+ label.form-check-label
26
+ input.form-check-input ( type ="radio" , name ="#{key} " , id ="#{key} -true" , value ="true" , checked =val .default , required )
27
+ span True
28
+ .form-check.form-check-inline
29
+ label.form-check-label
30
+ input.form-check-input ( type ="radio" , name ="#{key} " , id ="#{key} -false" , value ="false" , checked =! val .default , required )
31
+ span False
26
32
else if (val .type === " string" )
27
33
.form-group.row
28
34
label.form-control-label.control-label.col-sm-3 ( for ="#{key} " ) #{key}
@@ -86,28 +92,20 @@ block scripts
86
92
}
87
93
}
88
94
}
89
- } else if ($el .attr (" pattern" )) {
90
- if (val !== " true" && val !== " false" ) {
91
- // Check bools
92
- $el .addClass (" form-control-error" );
93
- $formGroup .addClass (" has-error" );
94
- hasErrors = true ;
95
- } else {
96
- // Convert bools
95
+ } else if ($el .attr (" type" ) === " radio" ) {
96
+ // Convert bools
97
+ if ($el .is (" :checked" )) {
97
98
val = (val === " true" );
98
99
$el .addClass (" form-control-success" );
99
100
$formGroup .addClass (" has-success" );
100
- }
101
- } else {
102
- if (val === " " ) {
103
- // Check strings
104
- $el .addClass (" form-control-error" );
105
- $formGroup .addClass (" has-error" );
106
- hasErrors = true ;
107
101
} else {
108
- $el . addClass ( " form-control-success " );
109
- $formGroup . addClass ( " has-success " );
102
+ // Prevent "false" overwriting true
103
+ val = (val === " false " );
110
104
}
105
+ } else {
106
+ // Do not check enums or strings (allow empty)
107
+ $el .addClass (" form-control-success" );
108
+ $formGroup .addClass (" has-success" );
111
109
}
112
110
formObj[name] = val; // Set key and value
113
111
});
0 commit comments