Question T12716
Visible to All Users

Question within panel with logic renders as visible incorrectly

created 2 years ago (modified 2 years ago)

Hi,

I have a scenario whereby there is a panel, which contains a checkbox question with several options. If one of those options is checked, there is logic to display a subsequent panel with another question. However, it seems like the question within that panel (which has logic) is always visible within the model regardless of which checkbox item is selected.

Consider the following reproducible example: https://codesandbox.io/s/withered-darkness-lqx61z?file=/src/json.js1.

Within the first panel, there are 5 options. If "first item" is selected, the survey renders another panel with another question "first question with logic". If another item is selected, for example "second item", the survey doesn't render the panel as expected. However, in the actual model, by console logging the visible questions, you can see that "first question with logic" is always considered visible, regardless of which checkbox item is selected. This is reproducible on the above code sandbox as I mentioned.

Could you please look into this and confirm that it is indeed a bug?

For your reference, I have included an included an example within the same code sandbox that works fine. It's a simple boolean question, that when 'yes' is selected, displays the correct question and indeed shows it as visible within the model only when applicable.

Answers approved by surveyjs Support

created 2 years ago

Hello Mo,
Thank you for the comprehensive explanation and the demo.
To achieve your goal, it is required to modify the visibleIf expression of the Panel based on first item element and use the contains operator instead:

Code
{ type: "panel", name: "Panel based on first item", elements: [ { type: "text", name: "First question within logic", title: "First question within logic.", titleLocation: "left", hideNumber: true, inputType: "number" } ], visibleIf: "{Checkbox question as parent logic} contains ['First item']", title: "Details on first panel", showNumber: true }

Now, the panel appears if you select the first and second option as well. The updated example is available at https://codesandbox.io/s/fervent-jepsen-fzf59q?file=/src/json.js.

Please let me know if you have any questions or require further assistance.

    Show previous comments (5)

      Hi Mo,
      I believe all the required information is available in the onProgressText function options.
      For instance, the total number of visible questions is available as options.questionCount.
      The total number of visible answered questions is available as options.answeredQuestionCount.

      Please test the updated demo: https://codesandbox.io/s/affectionate-gianmarco-pdcqxq?file=/src/json.js.
      You can see that the _options.questionCount initially equals to 2. If you check the first checkbox item, the number will be changed to 3.

      Please let me know if these options settings can help you achieve your goal.

        Thank you so much for this Jane! I have tested the updated demo and both options.questionCount and options.answseredQuestionCount show the correct values.

        Thank you again!

          You're always welcome, Mo! Please feel free to contact us if you have any questions.