Skip to content

Commit cd01239

Browse files
Added data grid component to support array of objects
Signed-off-by: Natalia Luzuriaga <natalia.luzuriaga@cms.hhs.gov>
1 parent b8b485a commit cd01239

2 files changed

Lines changed: 34 additions & 9 deletions

File tree

js/generateFormComponents.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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";
@@ -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,6 +189,24 @@ 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
}
@@ -197,7 +220,6 @@ function createFormHeading(title, description) {
197220
function createAllComponents(schema, prefix = ""){
198221
let components = [];
199222

200-
console.log("checking schema", schema);
201223

202224
if (schema.type === "object" && schema.properties) {
203225
for (const [key, value] of Object.entries(schema.properties)) {
@@ -208,7 +230,10 @@ function createAllComponents(schema, prefix = ""){
208230

209231
if (fieldComponent.type === "container") {
210232
fieldComponent.components = createAllComponents(value, fullKey);
233+
} else if (fieldComponent.type === "datagrid") {
234+
fieldComponent.components = createAllComponents(value.items, fullKey);
211235
}
236+
212237
components.push(fieldComponent);
213238
}
214239
}

schemas/schema-0.0.0.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@
4242
"items": {
4343
"type": "object",
4444
"properties": {
45-
"URL": {
46-
"type": "string",
47-
"format": "uri",
48-
"description": "The URL of the release license"
49-
},
5045
"name": {
5146
"type": "string",
5247
"enum": [
@@ -66,11 +61,16 @@
6661
"None"
6762
],
6863
"description": "An abbreviation for the name of the license"
64+
},
65+
"URL": {
66+
"type": "string",
67+
"format": "uri",
68+
"description": "The URL of the release license"
6969
}
7070
},
7171
"required": [
72-
"url",
73-
"name"
72+
"name",
73+
"URL"
7474
]
7575
}
7676
},

0 commit comments

Comments
 (0)