Skip to content

Commit 6ff78cc

Browse files
authored
Merge pull request #16 from saicheck2233/new_AddSupportForCheckbox
Enhancement: Add support for checkbox input
2 parents ec0701d + 16ba3f5 commit 6ff78cc

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/css/brutusin-json-forms.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ form.brutusin-form table, form.brutusin-form input, form.brutusin-form select, f
6565
min-width: 80px;
6666
}
6767

68-
form.brutusin-form input[type=radio] {
68+
form.brutusin-form input[type=radio], form.brutusin-form input[type=checkbox] {
6969
margin: 0 15px 0 10px;
7070
}
7171

src/js/brutusin-json-forms.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,28 @@ if (typeof brutusin === "undefined") {
395395
appendChild(input, radioInput, s);
396396
}
397397
}
398+
else if (s.format === "checkbox") {
399+
input = document.createElement("div");
400+
for (var i = 0; i < s.enum.length; i++) {
401+
checkbox = document.createElement("input");
402+
checkbox.type = "checkbox";
403+
checkbox.name = s.enum[i];
404+
checkbox.value = s.enum[i];
405+
406+
var label = document.createElement("label");
407+
label.htmlFor = s.enum[i];
408+
var labelText = document.createTextNode(s.enum[i]);
409+
appendChild(label, labelText);
410+
if (value && s.enum[i] === value) {
411+
checkbox.checked = true;
412+
}
413+
if (s.readOnly) {
414+
checkbox.disabled = true;
415+
}
416+
appendChild(input, label);
417+
appendChild(input, checkbox, s);
418+
}
419+
}
398420
else if (s.required) {
399421
input = document.createElement("input");
400422
input.type = "checkbox";

0 commit comments

Comments
 (0)