diff --git a/src/css/brutusin-json-forms.css b/src/css/brutusin-json-forms.css index d863628..4e1290c 100644 --- a/src/css/brutusin-json-forms.css +++ b/src/css/brutusin-json-forms.css @@ -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; } diff --git a/src/js/brutusin-json-forms.js b/src/js/brutusin-json-forms.js index 25a0bb6..c94413a 100644 --- a/src/js/brutusin-json-forms.js +++ b/src/js/brutusin-json-forms.js @@ -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";