@@ -318,9 +318,39 @@ if (typeof brutusin === "undefined") {
318
318
renderers [ "boolean" ] = function ( container , id , parentObject , propertyProvider , value ) {
319
319
var schemaId = getSchemaId ( id ) ;
320
320
var s = getSchema ( schemaId ) ;
321
- var input = document . createElement ( "input" ) ;
322
- input . type = "checkbox" ;
323
- input . schema = schemaId ;
321
+ var input ;
322
+ if ( s . required ) {
323
+ input = document . createElement ( "input" ) ;
324
+ input . type = "checkbox" ;
325
+ if ( value === true ) {
326
+ input . checked = true ;
327
+ }
328
+ } else {
329
+ input = document . createElement ( "select" ) ;
330
+ var emptyOption = document . createElement ( "option" ) ;
331
+ var textEmpty = document . createTextNode ( "" ) ;
332
+ textEmpty . value = "" ;
333
+ appendChild ( emptyOption , textEmpty , s ) ;
334
+ appendChild ( input , emptyOption , s ) ;
335
+
336
+ var optionTrue = document . createElement ( "option" ) ;
337
+ var textTrue = document . createTextNode ( "true" ) ;
338
+ textTrue . value = "true" ;
339
+ appendChild ( optionTrue , textTrue , s ) ;
340
+ appendChild ( input , optionTrue , s ) ;
341
+
342
+ var optionFalse = document . createElement ( "option" ) ;
343
+ var textFalse = document . createTextNode ( "false" ) ;
344
+ textFalse . value = "false" ;
345
+ appendChild ( optionFalse , textFalse , s ) ;
346
+ appendChild ( input , optionFalse , s ) ;
347
+
348
+ if ( value === true ) {
349
+ input . selectedIndex = 1 ;
350
+ } else if ( value === false ) {
351
+ input . selectedIndex = 2 ;
352
+ }
353
+ }
324
354
input . onchange = function ( ) {
325
355
if ( parentObject ) {
326
356
parentObject [ propertyProvider . getValue ( ) ] = getValue ( s , input ) ;
@@ -329,9 +359,7 @@ if (typeof brutusin === "undefined") {
329
359
}
330
360
onDependencyChanged ( schemaId , input ) ;
331
361
} ;
332
- if ( value === true ) {
333
- input . checked = true ;
334
- }
362
+ input . schema = schemaId ;
335
363
input . id = getInputId ( ) ;
336
364
inputCounter ++ ;
337
365
if ( s . description ) {
@@ -772,39 +800,44 @@ if (typeof brutusin === "undefined") {
772
800
} ;
773
801
774
802
obj . getData = function ( ) {
775
- function removeEmptiesAndNulls ( object ) {
803
+ function removeEmptiesAndNulls ( object , schema ) {
776
804
if ( object instanceof Array ) {
777
805
if ( object . length === 0 ) {
778
806
return null ;
779
807
}
780
808
var clone = new Array ( ) ;
781
809
for ( var i = 0 ; i < object . length ; i ++ ) {
782
- clone [ i ] = removeEmptiesAndNulls ( object [ i ] ) ;
810
+ clone [ i ] = removeEmptiesAndNulls ( object [ i ] , schema . items ) ;
783
811
}
784
812
return clone ;
785
813
} else if ( object === "" ) {
786
814
return null ;
787
815
} else if ( object instanceof Object ) {
788
816
var clone = new Object ( ) ;
817
+ var nonEmpty = false ;
789
818
for ( var prop in object ) {
790
819
if ( prop . startsWith ( "$" ) && prop . endsWith ( "$" ) ) {
791
820
continue ;
792
821
}
793
- var value = removeEmptiesAndNulls ( object [ prop ] ) ;
822
+ var value = removeEmptiesAndNulls ( object [ prop ] , schema . properties [ prop ] ) ;
794
823
if ( value !== null ) {
795
824
clone [ prop ] = value ;
825
+ nonEmpty = true ;
796
826
}
797
827
}
798
- return clone ;
828
+ if ( nonEmpty || schema . required ) {
829
+ return clone ;
830
+ } else {
831
+ return null ;
832
+ }
799
833
} else {
800
834
return object ;
801
835
}
802
836
}
803
837
if ( ! container ) {
804
838
return null ;
805
839
} else {
806
- return removeEmptiesAndNulls ( data ) ;
807
- ;
840
+ return removeEmptiesAndNulls ( data , schema ) ;
808
841
}
809
842
} ;
810
843
@@ -1093,9 +1126,19 @@ if (typeof brutusin === "undefined") {
1093
1126
value = null ;
1094
1127
}
1095
1128
} else if ( schema . type === "boolean" ) {
1096
- value = input . checked ;
1097
- if ( ! value ) {
1098
- value = false ;
1129
+ if ( input . tagName . toLowerCase ( ) === "input" ) {
1130
+ value = input . checked ;
1131
+ if ( ! value ) {
1132
+ value = false ;
1133
+ }
1134
+ } else if ( input . tagName . toLowerCase ( ) === "select" ) {
1135
+ if ( input . value === "true" ) {
1136
+ value = true ;
1137
+ } else if ( input . value === "false" ) {
1138
+ value = false ;
1139
+ } else {
1140
+ value = null ;
1141
+ }
1099
1142
}
1100
1143
} else if ( schema . type === "any" ) {
1101
1144
if ( value ) {
0 commit comments