Question T4955
Visible to All Users

Checkbox Select All Behaving Badly When Multiple Questions on the Page have the same "valueName" value

created 4 years ago

Hi,

I needed to dynamically break up a question into multiple groups each with a unique question type. However, I gave each cloned question the same "valueName" value so that all the answers in each group could be mapped to the same JSON property. It seems to work fine, except that the select all is behaving weirdly. When I click "Select All" on one group/question, it seems to impact the other groups/ questions.

Clipboard-File-1.png

Answers approved by surveyjs Support

created 4 years ago

Hello Alan,
I guess, we can remove "Select All" selection in other check boxes. Here is the example with your issue. However, I am afraid this is not what you are looking for. Here is the issue. On setting "Select all", checkbox question create an array with all visible items and set it to question value. As result, it will unset all checks for other checkboxes, if there is not this type of values. If it is not unexpected behavior, then I suggest to create a calculated value that will join values for all your checkboxes. Here is the example.

Thank you,
Andrew
SurveyJS Team

    Show previous comments (4)

      Andrew,

      I ran into anther issue. In order for this to completely work for me, I need to build the calculatedValue expression dynamically. First I tried just updating the expression property, but the updated expression didn't get applied to the logic. I was able to confirm this by stepping through the code.

      Originally my calculated expression was:

      JavaScript
      "joinArrays({Question.IndustryExperience.600}, {Question.IndustryExperience.601}, {Question.IndustryExperience.602})"

      I then updated the expression dynamically before the survey is loaded to something like:

      JavaScript
      "joinArrays({Question.IndustryExperience.600}, {Question.IndustryExperience.601}, {Question.IndustryExperience.602}, {Question.IndustryExperience.602}, {Question.IndustryExperience.603}, {Question.IndustryExperience.604}, {Question.IndustryExperience.605}, {Question.IndustryExperience.606}, {Question.IndustryExperience.607}, {Question.IndustryExperience.608} )"

      but when the joinArrays function gets fired off it's only being set 3 parameters (the first 3 questions), instead of the updated list of questions Arrays.

      I also tried just creating the entire calculatedValue property dynamically, but it seems it's getting ignored as well. I did verify that the Calculated Value is getting added to the Survey Model, but it seems like the Survey Model isn't aware of this. Just like the previous case, where the Survey Model wasn't aware of the updated Calculated Value expression.

      JavaScript
      try { var calculatedValue = new Survey.CalculatedValue(); calculatedValue.name = questionName; calculatedValue.expression = expression; survey.calculatedValues.push(calculatedValue); } catch (err) { alert(err); }

      Any ideas?

      Thanks,
      Alan

        Hello Alan,
        What version do you use? The latest version has an error with variables like: "Question.IndustryExperience.600", it believes that "600" is 600th element in the array. Here is the related issue.
        Could you try version 1.7.24, for example? We will release next minor with the fix shortly.

        Thank you,
        Andrew
        SurveyJS Team

          I am on version 1.7.25. I did revert to 1.7.24, but that didn't resolve the issue where I was updating an existing CalculateValue expression. However, that's not a problem for me as creating the entire CalculatedValue object on the fly seems to have worked just fine.

          Other Answers

          created 4 years ago

          Shoot, I realized what the issue was in building the entire CalculatedValue object. on the fly. I forgot to set the "includeIntoResult" property.

          Now, it works (but I'm still not sure what was happening when I tried to update an existing CalculatedValue property.

          JavaScript
          try { var calculatedValue = new Survey.CalculatedValue(); calculatedValue.name = questionName; calculatedValue.expression = expression; calculatedValue.includeIntoResult = true; survey.calculatedValues.push(calculatedValue); } catch (err) { alert(err); }
            Show previous comments (2)

              Hello Alan,
              You can change your function as in the example.

              Thank you,
              Andrew
              SurveyJS Team

                Andrew,

                Thanks so much. This is exactly what I wanted.

                I was actually trying to do something like this yesterday, but I coudn't figure out exactly how to do it get it to work. I didn't realize I could just use the "values" property to get all the selected answers.

                Alan.

                  Great, that it works now!

                  Andrew
                  SurveyJS Team