Skip to content

Commit

Permalink
Merge pull request #16 from saicheck2233/new_AddSupportForCheckbox
Browse files Browse the repository at this point in the history
Enhancement: Add support for checkbox input
  • Loading branch information
saicheck2233 authored Jul 11, 2023
2 parents ec0701d + 16ba3f5 commit 6ff78cc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/css/brutusin-json-forms.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ form.brutusin-form table, form.brutusin-form input, form.brutusin-form select, f
min-width: 80px;
}

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

Expand Down
22 changes: 22 additions & 0 deletions src/js/brutusin-json-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,28 @@ if (typeof brutusin === "undefined") {
appendChild(input, radioInput, s);
}
}
else if (s.format === "checkbox") {
input = document.createElement("div");
for (var i = 0; i < s.enum.length; i++) {
checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.name = s.enum[i];
checkbox.value = s.enum[i];

var label = document.createElement("label");
label.htmlFor = s.enum[i];
var labelText = document.createTextNode(s.enum[i]);
appendChild(label, labelText);
if (value && s.enum[i] === value) {
checkbox.checked = true;
}
if (s.readOnly) {
checkbox.disabled = true;
}
appendChild(input, label);
appendChild(input, checkbox, s);
}
}
else if (s.required) {
input = document.createElement("input");
input.type = "checkbox";
Expand Down

0 comments on commit 6ff78cc

Please sign in to comment.