5
5
*/
6
6
angular . module ( 'schemaForm' ) . provider ( 'schemaForm' ,
7
7
[ 'sfPathProvider' , function ( sfPathProvider ) {
8
+ var stripNullType = function ( type ) {
9
+ if ( Array . isArray ( type ) && type . length == 2 ) {
10
+ if ( type [ 0 ] === 'null' )
11
+ return type [ 1 ] ;
12
+ if ( type [ 1 ] === 'null' )
13
+ return type [ 0 ] ;
14
+ }
15
+ return type ;
16
+ }
8
17
9
18
//Creates an default titleMap list from an enum, i.e. a list of strings.
10
19
var enumToTitleMap = function ( enm ) {
@@ -35,7 +44,7 @@ angular.module('schemaForm').provider('schemaForm',
35
44
} ;
36
45
37
46
var defaultFormDefinition = function ( name , schema , options ) {
38
- var rules = defaults [ schema . type ] ;
47
+ var rules = defaults [ stripNullType ( schema . type ) ] ;
39
48
if ( rules ) {
40
49
var def ;
41
50
for ( var i = 0 ; i < rules . length ; i ++ ) {
@@ -88,7 +97,7 @@ angular.module('schemaForm').provider('schemaForm',
88
97
} ;
89
98
90
99
var text = function ( name , schema , options ) {
91
- if ( schema . type === 'string' && ! schema [ 'enum' ] ) {
100
+ if ( stripNullType ( schema . type ) === 'string' && ! schema [ 'enum' ] ) {
92
101
var f = stdFormObj ( name , schema , options ) ;
93
102
f . key = options . path ;
94
103
f . type = 'text' ;
@@ -100,7 +109,7 @@ angular.module('schemaForm').provider('schemaForm',
100
109
//default in json form for number and integer is a text field
101
110
//input type="number" would be more suitable don't ya think?
102
111
var number = function ( name , schema , options ) {
103
- if ( schema . type === 'number' ) {
112
+ if ( stripNullType ( schema . type ) === 'number' ) {
104
113
var f = stdFormObj ( name , schema , options ) ;
105
114
f . key = options . path ;
106
115
f . type = 'number' ;
@@ -110,7 +119,7 @@ angular.module('schemaForm').provider('schemaForm',
110
119
} ;
111
120
112
121
var integer = function ( name , schema , options ) {
113
- if ( schema . type === 'integer' ) {
122
+ if ( stripNullType ( schema . type ) === 'integer' ) {
114
123
var f = stdFormObj ( name , schema , options ) ;
115
124
f . key = options . path ;
116
125
f . type = 'number' ;
@@ -120,7 +129,7 @@ angular.module('schemaForm').provider('schemaForm',
120
129
} ;
121
130
122
131
var checkbox = function ( name , schema , options ) {
123
- if ( schema . type === 'boolean' ) {
132
+ if ( stripNullType ( schema . type ) === 'boolean' ) {
124
133
var f = stdFormObj ( name , schema , options ) ;
125
134
f . key = options . path ;
126
135
f . type = 'checkbox' ;
@@ -130,7 +139,7 @@ angular.module('schemaForm').provider('schemaForm',
130
139
} ;
131
140
132
141
var select = function ( name , schema , options ) {
133
- if ( schema . type === 'string' && schema [ 'enum' ] ) {
142
+ if ( stripNullType ( schema . type ) === 'string' && schema [ 'enum' ] ) {
134
143
var f = stdFormObj ( name , schema , options ) ;
135
144
f . key = options . path ;
136
145
f . type = 'select' ;
@@ -143,7 +152,7 @@ angular.module('schemaForm').provider('schemaForm',
143
152
} ;
144
153
145
154
var checkboxes = function ( name , schema , options ) {
146
- if ( schema . type === 'array' && schema . items && schema . items [ 'enum' ] ) {
155
+ if ( stripNullType ( schema . type ) === 'array' && schema . items && schema . items [ 'enum' ] ) {
147
156
var f = stdFormObj ( name , schema , options ) ;
148
157
f . key = options . path ;
149
158
f . type = 'checkboxes' ;
@@ -156,7 +165,7 @@ angular.module('schemaForm').provider('schemaForm',
156
165
} ;
157
166
158
167
var fieldset = function ( name , schema , options ) {
159
- if ( schema . type === 'object' ) {
168
+ if ( stripNullType ( schema . type ) === 'object' ) {
160
169
var f = stdFormObj ( name , schema , options ) ;
161
170
f . type = 'fieldset' ;
162
171
f . items = [ ] ;
@@ -188,7 +197,7 @@ angular.module('schemaForm').provider('schemaForm',
188
197
189
198
var array = function ( name , schema , options ) {
190
199
191
- if ( schema . type === 'array' ) {
200
+ if ( stripNullType ( schema . type ) === 'array' ) {
192
201
var f = stdFormObj ( name , schema , options ) ;
193
202
f . type = 'array' ;
194
203
f . key = options . path ;
@@ -386,7 +395,7 @@ angular.module('schemaForm').provider('schemaForm',
386
395
ignore = ignore || { } ;
387
396
globalOptions = globalOptions || { } ;
388
397
389
- if ( schema . type === 'object' ) {
398
+ if ( stripNullType ( schema . type ) === 'object' ) {
390
399
angular . forEach ( schema . properties , function ( v , k ) {
391
400
if ( ignore [ k ] !== true ) {
392
401
var required = schema . required && schema . required . indexOf ( k ) !== - 1 ;
0 commit comments