Skip to content

Commit

Permalink
Merge pull request #20 from saicheck2233/new_AddGetDataSupportForChec…
Browse files Browse the repository at this point in the history
…kbox

Enhancement: Add getData() support for checkbox
  • Loading branch information
saicheck2233 authored Jul 15, 2023
2 parents 5c1d69b + 209ff74 commit c78e8fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@
null,
"Required properties supported in both v3 and v4+ spec formats. Last one format takes preference. More info [here](https://github.com/brutusin/json-forms/issues/56)"],
["Radio button and checkbox",
{"$schema":"http://json-schema.org/draft-03/schema#","type":"object","properties":{"radio1":{"type":"boolean","format":"radio","title":"Animal","required":true,"enum":["Dog","Cat","Bird"]},"checkbox":{"type":"boolean","format":"checkbox","title":"Transportation","required":true,"enum":["Vehicle","Airplane","Cruise"]}}},
{"$schema":"http://json-schema.org/draft-03/schema#","type":"object","properties":{"radio1":{"type":"boolean","format":"radio","title":"Animal","required":true,"enum":["Dog","Cat","Bird"]},"checkbox":{"type":"boolean","format":"checkbox","title":"Transportation","required":true,"enum":["Vehicle","Airplane","Cruise"]}}},
null,
null,
"Boolean supporting radio and checkbox type. Must define `format` and `enum` fields."]
"Boolean supporting radio and checkbox type. Must define `format` and `enum` fields."],
["Additional input type format",
{"$schema":"http://json-schema.org/draft-03/schema#","type":"object","properties":{"password":{"title":"Password","type":"string","format":"password","description":"Password field would have the text masked.","required":true},"email":{"title":"Email","type":"string","format":"email","description":"Email field would need to follow the format of [email protected] in order to pass the validation.","required":true},"date":{"title":"Date","type":"string","format":"date","description":"Use the date picker to pick the date.","required":true},"time":{"title":"Time","type":"string","format":"time","description":"Use the time picker to pick the time.","required":true}}},
null,
Expand Down
16 changes: 16 additions & 0 deletions src/js/brutusin-json-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,9 @@ if (typeof brutusin === "undefined") {
if (object.length === 0) {
return null;
}
if (s.format === "checkbox") {
return object;
}
var clone = new Array();
for (var i = 0; i < object.length; i++) {
clone[i] = removeEmptiesAndNulls(object[i], s.items);
Expand Down Expand Up @@ -1394,6 +1397,19 @@ if (typeof brutusin === "undefined") {
if (!value) {
value = false;
}
} else if (schema.format === "checkbox") {
var checkboxValue = [];
for (var i = 0; i < input.childElementCount; i++) {
if (input.childNodes[i].tagName === "INPUT" && input.childNodes[i].checked) {
checkboxValue.push(input.childNodes[i].value);
}
}
if (checkboxValue.length !== 0) {
value = checkboxValue;
}
else {
value = null;
}
} else if (input.tagName.toLowerCase() === "select") {
if (input.value === "true") {
value = true;
Expand Down

0 comments on commit c78e8fb

Please sign in to comment.