formBuilder: Required checkbox group does not render checked values
Description:
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)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 6
- Comments: 15 (2 by maintainers)
Commits related to this issue
- Work around for https://github.com/kevinchappell/formBuilder/issues/910 — committed to Geometry-Pty-Ltd/formBuilder by instagibb 3 years ago
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.