question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Required checkbox group does not render checked values

See original GitHub issue

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)

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
instagibbcommented, Aug 26, 2020

This issue is pretty annoying. As far as I can tell this is caused by the following:

    if (type === 'checkbox-group' && data.required) {
      this.onRender = this.groupRequired
    }

on Line 35-37 of select.js

This replaces the onRender function later on in select.js which is responsible for setting the userData of the checkbox-group. I don’t understand what groupRequired is doing, but it never seems to even consider the userData.

0reactions
BenMosescommented, Jul 11, 2022

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:

  1. Link to Demo from above ^ https://codesandbox.io/s/stoic-zhukovsky-sbuhj?fontsize=14&file=/src/index.js
  2. Right hand side shows the bottom checkbox group is empty [Bug]
  3. Bottom left corner, under dependencies, change formBuilder to 3.8.3
  4. Right hand side now shows the bottom checkbox group to be filled [Fixed?]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Checkbox not Rendering or Changing Checked value when ...
I have used property 'checked' and assigned state's boolean value. So, it should render when state going to be changed but it not...
Read more >
<input>: The Input (Form Input) element - HTML
The <input> HTML element is used to create interactive controls for web-based forms in order to accept data from the user; a wide...
Read more >
lightning-input - documentation - Salesforce Developers
A lightning-input component creates an HTML <input> element. This component supports the following input types: checkbox; checkbox-button; date; datetime ...
Read more >
Checkbox Component - Appian 21.1
value. List of Variant. Values of choices to display as selected. ... Custom message to display when the field's value is required and...
Read more >
React Tutorial – How to Work with Multiple Checkboxes
But to display on the screen whether it's checked or not, ... So if the checkbox is checked, we're setting the isChecked value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found