@@ -26,6 +26,10 @@ function determineType(field) {
2626 if ( field . type === "object" ) {
2727 return "container" ;
2828 } else if ( field . type === "array" ) {
29+ // Array of objects
30+ if ( field . items . type === "object" ) {
31+ return "datagrid"
32+ }
2933 // Multi-select
3034 if ( field . items . hasOwnProperty ( "enum" ) ) {
3135 return "selectboxes" ;
@@ -37,9 +41,9 @@ function determineType(field) {
3741 return "radio" ;
3842 } else if ( field . type === "number" ) {
3943 return "number" ;
40- } else if ( field . type === "boolean" ) {
44+ } else if ( field . type === "boolean" ) {
4145 return "select-boolean" ;
42- } else if ( field . type === "string" ) {
46+ } else if ( field . type === "string" || field . type . includes ( "string" ) ) {
4347 if ( field . format == "date-time" ) {
4448 return "datetime" ;
4549 }
@@ -100,7 +104,8 @@ function createComponent(fieldName, fieldObject) {
100104 key : fieldName ,
101105 type : "radio" ,
102106 input : true ,
103- description : fieldObject [ "description" ]
107+ description : fieldObject [ "description" ] ,
108+ tooltip : fieldObject [ "description" ]
104109 } ;
105110 case "selectboxes" :
106111 var options = transformArrayToOptions ( fieldObject . items . enum ) ;
@@ -184,43 +189,69 @@ function createComponent(fieldName, fieldObject) {
184189 input : true ,
185190 components : [ ]
186191 } ;
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+ } ;
187210 default :
188211 break ;
189212 }
190213}
191214
215+ // Adds heading containing schema information
192216function createFormHeading ( title , description ) {
193217 const container = document . getElementById ( 'form-header' ) ;
194218 container . innerHTML = `<h1>${ title } </h1>\n<h2>${ description } </h2>` ;
195219}
196220
221+ // Iterates through each json field and creates component array for Form.io
197222function createAllComponents ( schema , prefix = "" ) {
198223 let components = [ ] ;
199224
200- console . log ( "checking schema" , schema ) ;
201-
202225 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 ) ) {
204230
231+ console . log ( "key at play:" , key ) ;
205232 const fullKey = prefix ? `${ prefix } .${ key } ` : key ;
206233
207234 var fieldComponent = createComponent ( key , value ) ;
208235
209236 if ( fieldComponent . type === "container" ) {
210237 fieldComponent . components = createAllComponents ( value , fullKey ) ;
238+ }
239+ else if ( fieldComponent . type === "datagrid" ) {
240+ fieldComponent . components = createAllComponents ( value . items , fullKey ) ;
211241 }
242+
212243 components . push ( fieldComponent ) ;
213244 }
214245 }
215246
216247 return components ;
217248}
218249
219- // Iterates through each json field and creates component array for Form.io
250+ // Creates complete form based on input json schema
220251async function createFormComponents ( ) {
221252 let components = [ ] ;
222253
223- const filePath = "schemas/schema.json" ;
254+ const filePath = "schemas/schema-0.0.0 .json" ;
224255 let jsonData = await retrieveFile ( filePath ) ;
225256 console . log ( "JSON Data:" , jsonData ) ;
226257
0 commit comments