Skip to content

Commit 5efe5ba

Browse files
Added support for array types
Signed-off-by: Natalia Luzuriaga <natalia.luzuriaga@cms.hhs.gov>
1 parent cd01239 commit 5efe5ba

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

js/generateFormComponents.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ function determineType(field) {
4141
return "radio";
4242
} else if (field.type === "number") {
4343
return "number";
44-
} else if (field.type === "boolean"){
44+
} else if (field.type === "boolean") {
4545
return "select-boolean";
46-
} else if (field.type === "string") {
46+
} else if (field.type === "string" || field.type.includes("string")) {
4747
if (field.format == "date-time") {
4848
return "datetime";
4949
}
@@ -220,20 +220,23 @@ function createFormHeading(title, description) {
220220
function createAllComponents(schema, prefix = ""){
221221
let components = [];
222222

223-
224223
if (schema.type === "object" && schema.properties) {
225-
for (const [key, value] of Object.entries(schema.properties)) {
224+
225+
let items = schema.properties.hasOwnProperty("items") ? schema.properties.items : schema.properties
226+
227+
for (const [key, value] of Object.entries(items)) {
226228

227229
const fullKey = prefix ? `${prefix}.${key}` : key;
228230

229231
var fieldComponent = createComponent(key, value);
230232

231233
if (fieldComponent.type === "container") {
232234
fieldComponent.components = createAllComponents(value, fullKey);
233-
} else if (fieldComponent.type === "datagrid") {
235+
}
236+
else if (fieldComponent.type === "datagrid") {
234237
fieldComponent.components = createAllComponents(value.items, fullKey);
235238
}
236-
239+
237240
components.push(fieldComponent);
238241
}
239242
}
@@ -245,7 +248,7 @@ function createAllComponents(schema, prefix = ""){
245248
async function createFormComponents() {
246249
let components = [];
247250

248-
const filePath = "schemas/schema.json";
251+
const filePath = "schemas/schema-0.0.0.json";
249252
let jsonData = await retrieveFile(filePath);
250253
console.log("JSON Data:", jsonData);
251254

0 commit comments

Comments
 (0)