Question T14188
Visible to All Users

Recursive question

created a year ago (modified a year ago)

Hello SurveyJS Team,

I have a Survey in which there is a loop question,

And i don't know how can i do it.

For Example :
I want to write the question once, and it is based on the options of a question before it. If 20 options are chosen, the question will be repeated twenty times, and each option will be in a
separate question.

Kind Regards,
Amro

Answers approved by surveyjs Support

created a year ago

Hello Amro,
You can use a Panel Dynamic question and the valueName property to create multiple questions for selected choices.

Consider this example:

JSON
{ "logoPosition": "right", "pages": [ { "name": "page1", "elements": [ { "type": "checkbox", "name": "fruit", "title": "Select your favourive fruits", "valueName": "fruitData", "choices": [ "Banana", "Apple", "Orange", "Mango", "Pineapple", { "value": "Item 1", "text": "Grape" } ], "valuePropertyName": "fruitValue" }, { "type": "paneldynamic", "name": "question2", "title": "Fruit details", "valueName": "fruitData", "templateElements": [ { "type": "text", "name": "question3", "title": "More information about: {panel.fruitValue}" } ], "templateTitle": "{panel.fruitValue}" } ] } ] }

Now, panels will be created automatically for selected choices.
Clipboard-File-1.png

Should you have any further questions, I'm here to help.

    Show previous comments (10)

      Hello Amro,
      Thank you for the update. You can add a question inside a panel which would terminate a survey. Subscribe to the survey.onDynamicPanelItemValueChanged event and terminate a survey if the user selected to terminate the survey. To complete the survey, you can call the survey.doComplete function.

      Please let me know if this API helps.

        JSON
        { "logoPosition": "right", "pages": [ { "name": "page1", "elements": [ { "type": "checkbox", "name": "fruit", "title": "Select your favourive options", "valueName": "optData", "choices": [ { "value": "Opt1", "text": "Opt 1" }, { "value": "Opt2", "text": "Opt 2" }, { "value": "Opt3", "text": "Opt 3" } ], "valuePropertyName": "optDataValue" }, { "type": "paneldynamic", "name": "question2", "title": "Details", "valueName": "optData", "templateElements": [ { "type": "boolean", "name": "q2", "title": "AAA?" }, { "type": "boolean", "name": "q3", "title": "AA?" }, { "type": "boolean", "name": "q4", "title": "AAAA?" }, { "type": "radiogroup", "name": "Q4", "title": "?do you want to continue", "hideNumber": true, "isRequired": true, "choices": [ { "value": "1", "text": "Yes" }, { "value": "2", "text": "No" } ] } ], "templateTitle": "{panel.optDataValue}", "templateTabTitle": "Panel {panel.optDataValue}", "allowAddPanel": false, "allowRemovePanel": false, "renderMode": "tab" } ] } ], "triggers": [ { "type": "complete", "expression": "{optData[0].Q4} = 2" } ] }

        You can see from the JSON file that if you choose the three options,
        Inside the panel you must evaluate the three options,
        And when adding the trigger at the level of a Q4,
        it only takes me out in Array 0, and I cannot add it at the level of all options.

          Hello Amro,
          Triggers cannot process values inside dynamic panels. Dynamic panels can have multiple values within inputs with the same name, however, when using triggers it is mandatory to reference a particular field. That is why I actually recommended that you handle this programmatically using the corresponding API. Please refer to my previous comment. Let me know if you require further assistance.

          Thanks