Required checkbox group does not render checked values
See original GitHub issueDescription:
A checkbox group that is required does not render saved checked values. The checkboxes render correctly if the checkbox group is not required.
Environment Details:
- formBuilder Version: 3.1.3
- Browser: Chrome
- OS: Win 10
Expected Behavior
The checkboxes should display as checked if the checkbox is present in the userData array.
Actual Behavior
The checkboxes do not show as checked for required checkbox groups.
Steps to Reproduce
var formData = [ { "type": "checkbox-group", "required": true, "label": "Checkbox Group", "name": "checkbox-group-1550096191629", "values": [{ "label": "Option 1", "value": "option-1" }, { "label": "Option 2", "value": "option-2" }], "userData": ["option-1"] }]; var formRenderOpts = { formData }; $('#fb-viewer').formRender(formRenderOpts);
I have implemented the following work-around, but I want to make sure I am not missing a configuration item somewhere.
var data = formData; if (typeof data !== 'object') { data = JSON.parse(data); } $.each(data, function (i, item) { if (item.type === "checkbox-group") { if (typeof item.required !== 'undefined' && item.required === true) { if (item.userData.length > 0) { $('.field-' + item.name).find('input').each(function (i, e) { if ($.inArray(e.value, item.userData) !== -1) { $(e).prop('checked', true); } }); } } } });
Screenshot - (optional)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:13 (2 by maintainers)

Top Related StackOverflow Question
This issue is pretty annoying. As far as I can tell this is caused by the following:
on Line 35-37 of
select.jsThis replaces the
onRenderfunction later on inselect.jswhich is responsible for setting theuserDataof the checkbox-group. I don’t understand whatgroupRequiredis doing, but it never seems to even consider theuserData.This issue looks like it’s fixed in the latest version?
Is it fixed or is there some side-affect? If it is fixed can we close this ticket and I will update to the latest version.
Steps: