From e3d777fee0301a2b39c0c277542c803fb69a97f7 Mon Sep 17 00:00:00 2001 From: "Jason.Chuah" Date: Sun, 9 Jul 2023 02:21:30 +0800 Subject: [PATCH 1/2] enhancement: add getdata support for checkbox --- src/js/brutusin-json-forms.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/js/brutusin-json-forms.js b/src/js/brutusin-json-forms.js index 1f99f9c..58ba371 100644 --- a/src/js/brutusin-json-forms.js +++ b/src/js/brutusin-json-forms.js @@ -885,6 +885,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); @@ -1331,6 +1334,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; From 209ff749f53df41d35ca8d228a980058aa403702 Mon Sep 17 00:00:00 2001 From: "Jason.Chuah" Date: Wed, 12 Jul 2023 10:29:33 +0800 Subject: [PATCH 2/2] merge index.html --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 7423331..656453d 100644 --- a/index.html +++ b/index.html @@ -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 name@domain.com 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,