Conditions in dynamic questions


                        
        
            Survey.StylesManager.applyTheme("defaultV2");
        



                
                    var json =  {
    questions:[
      {
        type: "matrixdynamic",
        name: "frameworksRateMatrix",
        "minRowCount": 4,
        "maxRowCount": 4,
        "valueName": "frameworksRate",
        title: "Please tells us about JavaScript frameworks you are using (Matrix Dynamic)",
        columns: [
          {
            "name": "framework",
            "title": "Framework",
            "cellType": "text",
            "readOnly": true
          },
          {
            name: "using",
            title: "Do you use it?",
            "isRequired": true,
            choices: [
              "Yes",
              "No"
            ],
            cellType: "radiogroup"
          },
          {
            name: "experience",
            title: "How long do you use it?",
            cellType: "dropdown",
            "visibleIf": "{row.using} = 'Yes'",
            "isRequired": true,
            choices: [
              {
                value: 5,
                text: "3-5 years"
              },
              {
                value: 2,
                text: "1-2 years"
              },
              {
                value: 1,
                text: "less then a year"
              }
            ]
          }
        ]
      },
        {
            type: "paneldynamic",
          name: "frameworksRatePanel",
          "minPanelCount":  4, "maxPanelCount":  4,
          "valueName":  "frameworksRate",
            title: "Please tells us about JavaScript frameworks you are using (Panel Dynamic)",
          templateElements: [
            {
              "name": "framework",
              "title": "Framework",
              "type": "text",
              "readOnly":  true
            },
            {
              name: "using",
              title: "Do you use it?",
              "type": "radiogroup",
              "colCount":  0,
              "startWithNewLine": false,
              "isRequired": true,
              choices: [
                "Yes",
                "No"
              ],
              cellType: "radiogroup"
            },
            {
              name: "experience",
              title: "How long do you use it?",
              "type": "dropdown",
              "visibleIf": "{panel.using} = 'Yes'",
              "isRequired": true,
              "startWithNewLine": false,
              choices: [
                {
                  value: 5,
                  text: "3-5 years"
                },
                {
                  value: 2,
                  text: "1-2 years"
                },
                {
                  value: 1,
                  text: "less then a year"
                }
              ]
            }
          ]
        }

    ]
};

                    window.survey = new Survey.Model(json);
                
        
            survey.onComplete.add(function(sender) {
            document.querySelector('#surveyResult').textContent =
            "Result JSON:\n" + JSON.stringify(sender.data, null, 3);
            });
        
survey.data = {'frameworksRate': [{'framework':'angular v1'},{'framework':'angular v2+'},{'framework':'react'}, {'framework':'vue'}]};
        
            $("#surveyElement").Survey({
            model: survey 
            });
        

                    
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Conditions in dynamic questions, jQuery Survey Library Example</title>
    
<meta name="viewport" content="width=device-width" />
    <script src="https://unpkg.com/jquery"></script>
    <script src="/DevBuilds/survey-jquery/survey.jquery.min.js"></script>
    <link href="/DevBuilds/survey-core/defaultV2.min.css" type="text/css" rel="stylesheet" />
    <link rel="stylesheet" href="./index.css">

</head>
<body style="margin: 0">
    
            <div id="surveyElement" style="display:inline-block;width:100%;">
            </div>
    <div id="surveyResult"></div>

<script type="text/javascript" src="./index.js"></script>

</body>
</html>

In this example we are using two questions bound to the same data. Their valueName property equals to "frameworksRate".
"How long do you use it?" cell in matrix and question in panel are shown based on "Do you use it?" question in corresponded row or panel.
To access the value of the current row/panel you have to use prefix row. or panel..
Example for a matrix column:

visibleIf: "{row.using} = 'Yes'"
Example for a question in dynamic panel
visibleIf: "{panel.using} = 'Yes'"

Why we use cookies.

This site uses cookies to make your browsing experience more convenient and personal. Cookies store useful information on your computer to help us improve the efficiency and relevance of our site for you. In some cases, they are essential to making the site work properly. By accessing this site, you consent to the use of cookies.

For more information, refer to DevSoft Baltic’ privacy policy and cookie policy.