@@ -23,7 +23,9 @@ function transformArrayToOptions(arr) {
2323}
2424
2525function determineType ( field ) {
26- if ( field . type === "array" ) {
26+ if ( field . type === "object" ) {
27+ return "container" ;
28+ } else if ( field . type === "array" ) {
2729 // Multi-select
2830 if ( field . items . hasOwnProperty ( "enum" ) ) {
2931 return "selectboxes" ;
@@ -148,7 +150,7 @@ function createComponent(fieldName, fieldObject) {
148150 "maxDate" : null
149151 } ,
150152 description : fieldObject [ "description" ]
151- }
153+ } ;
152154 case "select-boolean" :
153155 return {
154156 "label" : fieldName ,
@@ -171,7 +173,17 @@ function createComponent(fieldName, fieldObject) {
171173 "type" : "select" ,
172174 "input" : true ,
173175 description : fieldObject [ "description" ]
174- }
176+ } ;
177+ case "container" :
178+ return {
179+ label : fieldName ,
180+ tableView : false ,
181+ validateWhenHidden : false ,
182+ key : fieldName ,
183+ type : "container" ,
184+ input : true ,
185+ components : [ ]
186+ } ;
175187 default :
176188 break ;
177189 }
@@ -182,6 +194,28 @@ function createFormHeading(title, description) {
182194 container . innerHTML = `<h1>${ title } </h1>\n<h2>${ description } </h2>` ;
183195}
184196
197+ function createAllComponents ( schema , prefix = "" ) {
198+ let components = [ ] ;
199+
200+ console . log ( "checking schema" , schema ) ;
201+
202+ if ( schema . type === "object" && schema . properties ) {
203+ for ( const [ key , value ] of Object . entries ( schema . properties ) ) {
204+
205+ const fullKey = prefix ? `${ prefix } .${ key } ` : key ;
206+
207+ var fieldComponent = createComponent ( key , value ) ;
208+
209+ if ( fieldComponent . type === "container" ) {
210+ fieldComponent . components = createAllComponents ( value , fullKey ) ;
211+ }
212+ components . push ( fieldComponent ) ;
213+ }
214+ }
215+
216+ return components ;
217+ }
218+
185219// Iterates through each json field and creates component array for Form.io
186220async function createFormComponents ( ) {
187221 let components = [ ] ;
@@ -193,14 +227,7 @@ async function createFormComponents() {
193227
194228 createFormHeading ( jsonData [ "title" ] , jsonData [ "description" ] ) ;
195229
196- formFields = jsonData [ "properties" ] ;
197- console . log ( "form Fields:" , formFields ) ;
198-
199- for ( const key in formFields ) {
200- console . log ( `${ key } :` , formFields [ key ] ) ;
201- var fieldComponent = createComponent ( key , formFields [ key ] ) ;
202- components . push ( fieldComponent ) ;
203- }
230+ components = createAllComponents ( jsonData ) ;
204231
205232 // Add submit button to form
206233 components . push ( {
0 commit comments