Revealing and hiding questions
Sometimes it is useful to present one question to the respondent and, depending on how they answer, to present additional follow-up questions.
If all these questions are simple and short enough to be presented on one page, using the DisplayOrHide question style is a simple and very effective to do so.
This style provides a way to display or hide groups of questions on the same page depending on the value of another question. Respondents can toggle between the groups, and values are removed from inappropriate questions.
See the Examples place for a demonstration.
For example, a single choice radio button question named "smoke" could have a value of yes, no, and maybe. A drop down question named "smoke_frequency" asks participants how often they smoke. A text area question named "comment" asks respondents to elaborate. When the respondent first sees the questionnaire, they should only see question "smoke" and the others should be hidden. If they click on yes or maybe, the drop down appears. If they click on no, the drop down disappears and the comments box appears instead.
To achieve this effect, first create the questions as described.
Then, following those questions, create a question with style DisplayOrHide, using the HTML question type.
In the "Formula" field, enter the following:
The formula is constructed as follows.
The first line of the formula is the name of the condition question, whose value determines what questions to display and what questions to hide.
Each of the lines that follows includes an equal sign. To the left of the equal sign is a list of values, comma-separated. To the right of the equal sign is a list of affected questions, also comma-separated.
When the value of the condition question changes to a value listed to the left of the equal sign, the affected questions listed on the right side are displayed. When the value changes to another value on a different line, the previously shown questions are hidden and the new affected questions are shown.
Each condition is entered on a separate line. Multilpe conditions can be entered on the same line and separated by semicolons. Spaces can be used freely between items; smoke, smoke_frequency, and comments are question names.
So, in this example, when the page loads, neither smoke_frequency nor comments are displayed. Selecting yes or maybe displays smoke_frequency, and selecting no displays comments instead.
The list of questions to the right of the equal sign may contain just one question name, or a list of several question names separated by commas, like this:
yes = smoke_frequency, reason_for_smoking, attempts_to_quit_smoking
It can also contain a range of question names, so that all questions between the first and the last are included, like this:
yes = smoke_frequency - attempts_to_quit_smoking
Multiple conditions can be set up in the same pattern. The first line indicates the question name of the condition; subsequent lines indicate what questions to display or hide for different values of the condition.
The condition question can be of type: radio buttons, check boxes, dropdowns, text fields. So can the questions being displayed and hidden, including HTML.
Special values for radio button questions can be entered to the left of the equal sign: -other is used with radio button questions created with the "Other" option. -none is used with radio button questions created with the "None" option, or for when the user hasn't made a choice yet.
When used with a set of one or more check boxes, each value of the conditional question displays or hides the affected question independently of the other values.
The questions on the right side of the equal sign CAN be marked as "required" when created. In the smoking example, both smoke_frequency and comments can be required questions. The validation logic in ViewsFlash automatically disables validation for questions that are hidden by DisplayOrHide, and re-enables the validation when they are displayed again.
Required questions. Affected questions should not be marked as "required". To validate that a question which may or may not be displayed has been answered, use a Script action instead of "required".
To display or hide an entire matrix, refer to it as matrixname_ . A matrix's question names start with a matrix name; use that name with an underscore. Individual matrix rows can be displayed or hidden using the name of the question in that row, such as rate_service. It is not possible to display or hide just the header row or the explanatory text above the matrix.
To display or hide an entire grid, refer to it as gridname_. A grid's question names start with a grid name; use that name with an underscore. Individual grid rows cannot be displayed or hidden. However, individual questions in the grid can be, using the name of the question in that cell.
The set of lines that begins with the name of a condition question followed by a set of lines for each condition is called a condition block. Multilpe condition blocks can be included in one DisplayOrHide question. Blank lines can be inserted for readability.
The first line of a condition block usually includes just the name of the condition question, but it can also include special keywords that alter the behavior in specific ways. Use a colon to separate the name of the question from the keywords, and separate the keywords with commas.
showatstart When the page is first displayed, all questions listed in all the choices are hidden by default. This can be changed with this keyword, and all questions will be displayed instead.
In earlier versions, this keyword was "noneshow" and it can still be used.
remove or restore or preserve Use only one of these keywords, which control how to deal with selections and values entered into fields that are made visible but are then made invisible when the user changes the value of the condition question. In the smoking example used here, a user selects Yes and then enters a value into the smoke_frequency field; then he changes his mind and selects No. The remove keyword, which is the default, will remove the value from smoke_frequency immediately; if the user selects Yes again, he will have to re-enter the value for smoke_frequency.
The restore keyword changes this behavior so that he will not have to re-enter the value and the value will still be there when he changes his mind.
The preserve keyword behaves just like restore, with a difference: the value of the choices made in the hidden fields will be sent to ViewsFlash with the questionnaire and therefore be saved in its data, whereas neither remove or restore will send any data to ViewsFlash.
nested It is possible to have a hierarchical set of DisplayAndHide questions. For example, an initial question about age displays different sets of questions for younger and older people. Within the younger group, a question about the value of education triggers is used as a conditional questions for more detailed questions about school plans, and a similar pattern is used for adults and retirement options. When this parameter is used, the DisplayOrHide questions themselves can be specified in the initial question's choices, and the "nested" DisplayOrHide conditions will be evaluated and carried out. The net effect is that the user will always see only those choices that are meaningful. In earlier versions, this keyword was "recursive" and it can still be used.
disable Instead of making hidden questions disappear, this option leaves those questions visible but disables the controls so that they cannot be used and colors the entire question grey to indicate that the question is not applicable.