-
Notifications
You must be signed in to change notification settings - Fork 36
Showifs Special cases
Showifs are a convenient way to dynamically alter your study depending on your participant's answers. Items with a showif are only displayed if the condition specified in the showif is met.
This is a special case for a showif. Consider the following example:
You have a pretty tricky item and want to allow participants to decide whether they can answer it or not - in case they cannot, you want to hide the item. For that to work out, your participants must be able to see the item in question first and it has to vanish after they decide that they cannot answer it. The name of the item that asks your participants whether they can answer the tricky item or not would be check and the choices for that item would be 1 = yes and 2 =no.
So,the solution to your problem would be to add a showif to your tricky item that says:
typeof check = "undefined" || check == 1 //js_only
In this case, your tricky item is shown to your participants, as long as the check-item is undefined (aka not filled in) or was answered with "yes". The //js_only
is necessary, because you only want to check this item on the users' side.
In your item-sheet, it should look like this:
Aim: You first ask a question and a second follow-up question is only displayed if a specific answer (to the first question) was NOT chosen.
If you ask both questions on the same page (there is no submit-button between your first and your second item), you cannot use R code, but need javascript. Include the following in the showif column of your second item:
! (String(NAME_OF_YOUR_FIRST_ITEM).indexOf("NUMBER_OF_ANSWER") > -1) //js_only
Example:
The first item (name = live_with_whom) asks with whom participants live (choices are for example 1=children, 2=partner, 3=alone, 4=parents). Only if participants indicate they do not currently live with their parents (i.e. they do not pick choice 4 = parents), you also want to show a second item, e.g., when they moved out of their parents' home.
In this case, include the following in the showif column of your second item:
! (String(live_with_whom).indexOf("4") > -1) //js_only
Because of formr's privacy model, data from previous surveys and previous survey pages is never directly re-exposed to the user/browser. This means that showifs that are supposed to trigger immediately on the same page but refer to previous answers on the same page AND in previous surveys are more complicated to set up. What you need are items of type hidden. They allow you to deliberately expose data from previous surveys (be careful when you do this). Here's an example.
We assume that a question about relationships was answered in a demographics questionnaire.
type | name | label | value | showif |
---|---|---|---|---|
hidden | mom_alive | demographics$mom_alive | ||
check | conflict | Did you have a conflict with someone today? | ||
check | conflict_mom | Did you have a conflict with your mom today? | mom_alive == 1 & conflict == 1 | |
check | conflict_others | Did you have a conflict with a friend today? | conflict == 1 |
Caution! You have to define hidden items new after each submit, if you want to use them there too. Furthermore, if you want to combine current survey's answers before the submit button and after, you have to define also hidden items for these previous current survey items. Here's an example (survey is called "sociodemographic").
type | name | label | value | showif |
---|---|---|---|---|
hidden | mom_alive | demographics$mom_alive | ||
check | conflict | Did you have a conflict with someone today? | ||
check | conflict_mom | Did you have a conflict with your mom today? | mom_alive == 1 & conflict == 1 | |
submit | submit_1 | Go on | ||
hidden | mom_alive2 | demographics$mom_alive | ||
hidden | conflict2 | sociodemographic$conflict | ||
check | conflict_mom2 | Did you have a conflict with your mum yesterday too? | mom_alive2 == 1 & conflict2 == 1 |