Skip to content

Commit 6e9f0cf

Browse files
Added select box component to support multi-select fields
Signed-off-by: Natalia Luzuriaga <natalia.luzuriaga@cms.hhs.gov>
1 parent d1ce529 commit 6e9f0cf

4 files changed

Lines changed: 54 additions & 10 deletions

File tree

js/formDataToJson.js

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,41 @@ async function retrieveFile(filePath) {
1616

1717
// Populates blank code.json object with values from form
1818
function populateObject(data, blankObject) {
19-
for (let key in data) {
20-
console.log("current key", key);
21-
console.log("check if value exists", data.hasOwnProperty(key));
19+
20+
for (const key in data) {
2221
if (blankObject.hasOwnProperty(key)) {
23-
if (typeof data[key] === "object" && data[key] !== null) {
24-
// If object, recursively populate
25-
// TODO: test out for permissions and description objects
26-
populateObject(data[key], blankObject[key]);
27-
} else {
28-
// Add value
22+
console.log(`${key}: ${data[key]}`);
23+
24+
if(typeof data[key] === "object" && isMultiSelect(data[key])) {
25+
blankObject[key] = getSelectedOptions(data[key]);
26+
}
27+
else {
2928
blankObject[key] = data[key];
3029
}
30+
31+
}
32+
}
33+
}
34+
35+
function isMultiSelect(obj) {
36+
for (const key in obj) {
37+
if (typeof obj[key] !== 'boolean') {
38+
return false;
39+
}
40+
}
41+
return true; // Return true if all values are booleans
42+
}
43+
44+
// Convert from dictionary to array
45+
function getSelectedOptions(options) {
46+
let selectedOptions = [];
47+
48+
for (let key in options) {
49+
if(options[key]) {
50+
selectedOptions.push(key);
3151
}
3252
}
53+
return selectedOptions;
3354
}
3455

3556
async function populateCodeJson(data) {

js/generateFormComponents.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ function createComponent(fieldName, fieldObject) {
8181
type: "radio",
8282
input: true,
8383
};
84+
case "selectboxes":
85+
var options = transformArrayToOptions(fieldObject.items.enum);
86+
console.log("checking options here:", options);
87+
return {
88+
label: fieldName,
89+
optionsLabelPosition: "right",
90+
tableView: false,
91+
values: options,
92+
validateWhenHidden: false,
93+
key: fieldName,
94+
type: "selectboxes",
95+
input: true,
96+
inputType: "checkbox"
97+
};
8498
default:
8599
break;
86100
}

schemas/schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
"laborHours": {
3939
"type": "number",
4040
"description": "Labor hours invested in the project"
41+
},
42+
"platforms": {
43+
"type": "array",
44+
"description": "Platforms supported by the project",
45+
"items": {
46+
"type": "string",
47+
"enum": ["web", "windows", "mac", "linux", "ios", "android", "other"]
48+
}
4149
}
4250
}
4351
}

schemas/template-code.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"status": "",
55
"organization": "",
66
"vcs": "",
7-
"laborHours": 0
7+
"laborHours": 0,
8+
"platforms": [ "" ]
89
}

0 commit comments

Comments
 (0)