@@ -26,6 +26,10 @@ function determineType(field) {
26
26
if ( field . type === "object" ) {
27
27
return "container" ;
28
28
} else if ( field . type === "array" ) {
29
+ // Array of objects
30
+ if ( field . items . type === "object" ) {
31
+ return "datagrid"
32
+ }
29
33
// Multi-select
30
34
if ( field . items . hasOwnProperty ( "enum" ) ) {
31
35
return "selectboxes" ;
@@ -37,9 +41,9 @@ function determineType(field) {
37
41
return "radio" ;
38
42
} else if ( field . type === "number" ) {
39
43
return "number" ;
40
- } else if ( field . type === "boolean" ) {
44
+ } else if ( field . type === "boolean" ) {
41
45
return "select-boolean" ;
42
- } else if ( field . type === "string" ) {
46
+ } else if ( field . type === "string" || field . type . includes ( "string" ) ) {
43
47
if ( field . format == "date-time" ) {
44
48
return "datetime" ;
45
49
}
@@ -100,7 +104,8 @@ function createComponent(fieldName, fieldObject) {
100
104
key : fieldName ,
101
105
type : "radio" ,
102
106
input : true ,
103
- description : fieldObject [ "description" ]
107
+ description : fieldObject [ "description" ] ,
108
+ tooltip : fieldObject [ "description" ]
104
109
} ;
105
110
case "selectboxes" :
106
111
var options = transformArrayToOptions ( fieldObject . items . enum ) ;
@@ -184,43 +189,69 @@ function createComponent(fieldName, fieldObject) {
184
189
input : true ,
185
190
components : [ ]
186
191
} ;
192
+ case "datagrid" :
193
+ return {
194
+ label : fieldName ,
195
+ reorder : false ,
196
+ addAnotherPosition : "bottom" ,
197
+ layoutFixed : false ,
198
+ enableRowGroups : false ,
199
+ initEmpty : false ,
200
+ tableView : false ,
201
+ defaultValue : [
202
+ { }
203
+ ] ,
204
+ validateWhenHidden : false ,
205
+ key : fieldName ,
206
+ type : "datagrid" ,
207
+ input : true ,
208
+ components : [ ]
209
+ } ;
187
210
default :
188
211
break ;
189
212
}
190
213
}
191
214
215
+ // Adds heading containing schema information
192
216
function createFormHeading ( title , description ) {
193
217
const container = document . getElementById ( 'form-header' ) ;
194
218
container . innerHTML = `<h1>${ title } </h1>\n<h2>${ description } </h2>` ;
195
219
}
196
220
221
+ // Iterates through each json field and creates component array for Form.io
197
222
function createAllComponents ( schema , prefix = "" ) {
198
223
let components = [ ] ;
199
224
200
- console . log ( "checking schema" , schema ) ;
201
-
202
225
if ( schema . type === "object" && schema . properties ) {
203
- for ( const [ key , value ] of Object . entries ( schema . properties ) ) {
226
+
227
+ let items = schema . properties . hasOwnProperty ( "items" ) ? schema . properties . items : schema . properties
228
+
229
+ for ( const [ key , value ] of Object . entries ( items ) ) {
204
230
231
+ console . log ( "key at play:" , key ) ;
205
232
const fullKey = prefix ? `${ prefix } .${ key } ` : key ;
206
233
207
234
var fieldComponent = createComponent ( key , value ) ;
208
235
209
236
if ( fieldComponent . type === "container" ) {
210
237
fieldComponent . components = createAllComponents ( value , fullKey ) ;
238
+ }
239
+ else if ( fieldComponent . type === "datagrid" ) {
240
+ fieldComponent . components = createAllComponents ( value . items , fullKey ) ;
211
241
}
242
+
212
243
components . push ( fieldComponent ) ;
213
244
}
214
245
}
215
246
216
247
return components ;
217
248
}
218
249
219
- // Iterates through each json field and creates component array for Form.io
250
+ // Creates complete form based on input json schema
220
251
async function createFormComponents ( ) {
221
252
let components = [ ] ;
222
253
223
- const filePath = "schemas/schema.json" ;
254
+ const filePath = "schemas/schema-0.0.0 .json" ;
224
255
let jsonData = await retrieveFile ( filePath ) ;
225
256
console . log ( "JSON Data:" , jsonData ) ;
226
257
0 commit comments