@@ -15,12 +15,34 @@ async function retrieveFile(filePath) {
1515 }
1616}
1717
18- // Creates Form.io component based on json fields
19- // Supports text field for now
20- // TODO: Create components for number, select, and multi-select
18+ function transformArrayToOptions ( arr ) {
19+ return arr . map ( ( item ) => ( {
20+ label : item . toString ( ) ,
21+ value : item . toString ( ) ,
22+ } ) ) ;
23+ }
24+
25+ function determineType ( field ) {
26+ if ( field . type === "array" ) {
27+ // TODO: Implement multi-select fields
28+ if ( field . items . hasOwnProperty ( "enum" ) ) {
29+ return "selectboxes" ;
30+ }
31+ return "array-textfield" ;
32+ } else if ( field . hasOwnProperty ( "enum" ) ) {
33+ return "radio" ;
34+ } else if ( field . type === "number" ) {
35+ return "number" ;
36+ } else if ( field . type === "string" ) {
37+ return "textfield" ;
38+ }
39+ }
40+
41+ // Creates Form.io component based on json field type
2142function createComponent ( fieldName , fieldObject ) {
22- switch ( fieldObject [ "type" ] ) {
23- case "string" :
43+ var componentType = determineType ( fieldObject ) ;
44+ switch ( componentType ) {
45+ case "textfield" :
2446 return {
2547 type : "textfield" ,
2648 key : fieldName ,
@@ -29,6 +51,36 @@ function createComponent(fieldName, fieldObject) {
2951 tooltip : fieldObject [ "description" ] ,
3052 description : fieldObject [ "description" ] ,
3153 } ;
54+ case "number" :
55+ return {
56+ label : fieldName ,
57+ applyMaskOn : "change" ,
58+ mask : false ,
59+ tableView : false ,
60+ delimiter : false ,
61+ requireDecimal : false ,
62+ inputFormat : "plain" ,
63+ truncateMultipleSpaces : false ,
64+ validateWhenHidden : false ,
65+ key : fieldName ,
66+ type : "number" ,
67+ input : true ,
68+ description : fieldObject [ "description" ] ,
69+ } ;
70+ case "radio" :
71+ var options = transformArrayToOptions ( fieldObject . enum ) ;
72+ console . log ( "checking options here:" , options ) ;
73+ return {
74+ label : fieldName ,
75+ optionsLabelPosition : "right" ,
76+ inline : false ,
77+ tableView : false ,
78+ values : options ,
79+ validateWhenHidden : false ,
80+ key : fieldName ,
81+ type : "radio" ,
82+ input : true ,
83+ } ;
3284 default :
3385 break ;
3486 }
0 commit comments