Skipping multiple question in surveys

Installation Forum (Inactive)
Skipping multiple question in surveys patrickbkeating1  2015-10-28 14:46
Status: Closed
 
Hello all,

I'm a new user to LabKey and I will be using it mostly to collect survey data.

I'm trying to do the following:

Q1. Were you sick? Yes/No

If yes, answer questions 2-5
If no, answer question 6

I'm able to use the skip logic on one question at a time, but wondering if it's possible to apply the skip logic to multiple questions as a group?
Thanks!
Patrick
 
 
Jon (LabKey DevOps) responded:  2015-10-29 12:58
Hi Patrick,

How are you setting up your skip logic currently? It doesn't seem too far off to apply the same skip logic to a group if you change your scope.

Regards,

Jon
 
patrickbkeating1 responded:  2015-10-29 13:05
Hi Jon,

Thanks for your response.
I used the sample skip logic code provided here https://www.labkey.org/wiki/home/Documentation/page.view?name=questionMetadata
I've slightly modified it e.g. something like below where the question "symptoms" only appears if "sick"=yes

I'm wondering if it's possible to move the "listener" outside of a question group, but haven't managed.
What would you suggest?

{
    "jsonType": "string",
    "width": 800,
    "inputType": "text",
    "name": "symptoms",
    "caption": "String Field",
    "shortCaption": "String Field",
    "required": false,
    "hidden": true,
    "listeners" : {
       "change" : {
          "question" : "sick",
          "fn" : "function(me, cmp, newValue, oldValue){if (me) me.setVisible(newValue == 'Yes');} "
        }
    }
}

Thanks a lot!
Patrick
 
Jon (LabKey DevOps) responded:  2015-10-29 16:38
Hi Patrick,

So you could just add a listener to every question, then enable the "hidden" option to true on each one to accomplish what you want.

So if you stuck this into every question other than the first one asking if they're sick:

"hidden": true,
    "listeners" : {
       "change" : {
          "question" : "sick",
          "fn" : "function(me, cmp, newValue, oldValue){if (me) me.setVisible(newValue == 'ANSWER');} "
        }
    }

Then, you set the newValue to Yes or No depending on which ones you want triggered.

I created a very basic example of this using the details you provided. Only questions 2-5 trigger for Yes and only question 6 will respond to No.

{
  "survey" : {
    "layout" : "auto",
    "showCounts" : false,
    "sections" : [ {
      "questions" : [{
        "name" : "Sick",
        "caption" : "Sick",
        "shortCaption" : "Sick",
        "hidden" : false,
        "jsonType" : "string",
        "inputType" : "textarea",
        "required" : false,
        "width" : 800
      },{
        "name" : "Age",
        "caption" : "Age",
        "shortCaption" : "Age",
        "hidden" : false,
        "jsonType" : "int",
        "inputType" : "text",
        "required" : false,
        "width" : 800,
        "hidden": true,
        "listeners" : {
            "change" : {
          "question" : "sick",
          "fn" : "function(me, cmp, newValue, oldValue){if (me) me.setVisible(newValue == 'Yes');} "
        }
      }
      }, {
        "name" : "Weight",
        "caption" : "Weight",
        "shortCaption" : "Weight",
        "hidden" : false,
        "jsonType" : "string",
        "inputType" : "text",
        "required" : false,
        "width" : 800,
        "hidden": true,
        "listeners" : {
            "change" : {
          "question" : "sick",
          "fn" : "function(me, cmp, newValue, oldValue){if (me) me.setVisible(newValue == 'Yes');} "
        }
      }
      }, {
        "name" : "Gender",
        "caption" : "Gender",
        "shortCaption" : "Gender",
        "hidden" : false,
        "jsonType" : "string",
        "inputType" : "text",
        "required" : false,
        "width" : 800,
        "hidden": true,
        "listeners" : {
            "change" : {
          "question" : "sick",
          "fn" : "function(me, cmp, newValue, oldValue){if (me) me.setVisible(newValue == 'Yes');} "
        }
      }
      }, {
        "name" : "DaysSick",
        "caption" : "Days Sick",
        "shortCaption" : "Days Sick",
        "hidden" : false,
        "jsonType" : "string",
        "inputType" : "text",
        "required" : false,
        "width" : 800,
        "hidden": true,
        "listeners" : {
            "change" : {
          "question" : "sick",
          "fn" : "function(me, cmp, newValue, oldValue){if (me) me.setVisible(newValue == 'Yes');} "
        }
      }
      }, {
        "name" : "MedsTaken",
        "caption" : "Meds Taken",
        "shortCaption" : "Meds Taken",
        "hidden" : false,
        "jsonType" : "string",
        "inputType" : "text",
        "required" : false,
        "width" : 800,
        "hidden": true,
        "listeners" : {
            "change" : {
          "question" : "sick",
          "fn" : "function(me, cmp, newValue, oldValue){if (me) me.setVisible(newValue == 'Yes');} "
        }
      }
      }, {
        "name" : "LastIllness",
        "caption" : "Last Illness",
        "shortCaption" : "Last Illness",
        "hidden" : false,
        "jsonType" : "string",
        "inputType" : "text",
        "required" : false,
        "width" : 800,
        "hidden": true,
        "listeners" : {
            "change" : {
          "question" : "sick",
          "fn" : "function(me, cmp, newValue, oldValue){if (me) me.setVisible(newValue == 'No');} "
        }
      }
      }],
      "description" : null,
      "header" : true,
      "title" : "medical",
      "collapsible" : true,
      "defaultLabelWidth" : 350
    } ]
  }
}
 
patrickbkeating1 responded:  2015-10-29 16:59
Hi Jon!

Thank you very much for this!!!
I'll incorporate it tomorrow!
Thanks again!
Patrick