Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Add getData() support for checkbox #20

Merged
merged 3 commits into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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