Conditional statements allow you to display sections in a form when certain conditions are met. For example, if you want to change the flow of the form depending on what answer the user provides.
Conditional statements work with 'yes/no', 'multiple choice' and 'checkbox' widgets. The widget that can appear or disappear depending on the answers provided is a 'section' widget. Please read through the steps and see an example form below.
Step 1
In 'advanced settings' for the widget assign a variable name. The name is a memorable string. No spaces are allowed. Examples:
If the 'yes/no' question is "are you a UK resident", you may want to call the widget "UK_resident".
In a multiple choice question "Which country do you come from" the answers may be "UK", "Poland", "Germany", "Other". The variable name may be "Country".
In a checkboxes question "Which products are you interested in", the answers may be "Annual report", "VAT", "Bookkeeping". The variable name may be "Product".
Step 2
Add sections or other widgets which are supposed to appear when a certain answer is provided. For a simple yes/no questions you could add questions that should appear when the answer is 'yes' and other questions when the answer is 'no'.
Step 3
Match the sections with appropriate answers. Go to advanced settings of each section. In the conditional statement field (in advanced settings) write the condition. The way you write the condition depends on the type of widget the answer is coming from:
For yes/no widgets the condition should be: variable_name==true or variable_name==false; For example UK_resident==true. Please note that double equals sign designates equality.
For multiple choice widgets, a variable is an object with properties "text" and "index".
For example: Country.text == "UK" or Country.index == 0
โReferring to the example 2 above if the condition is "Country chosen is Poland" the condition would be Country.text=="Poland". If the condition is "Third option was chosen", the condition would be Country.index == 2 (yes, this is correct, the index of the first item is 0, the index of the second item is 1 etc.)
For checkboxes you need to list the choices you are interested in; Referring to example 3 above
If the variable name is Product, the first choice would be Product[0], the second choice would be Product[1] and so on.
If the condition is "VAT was chosen", the condition you write would be Product[1]==true.
If the condition is "Annual report OR VAT was chosen" the condition would be "Any" for two expressions: Product[0]==true and Product[1]==true.
If the condition is "Annual report AND VAT was chosen" the condition would be "All" for two expressions: Product[0]==true and Product[1]==true.
For Country widget you need to reference a particular selection. There are several ways of doing it. We rank them below in order of our preference:
If the variable is Country, and the condition should be "if the United States is chosen" use one of these option:
Country.name == "United States of America"
Country.alpha3code == "USA"
Country.alpha2code == "US"
We prefer the first option because, although it requires most typing, can be easily picked up from the country list that the widget show.
Example form:
Note that the conditional statements can work with more complex structures. For example:
Conditional statements can refer to variables that are embedded in sections. In this case you need to make sure that you add a variable name to each section that holds the source variable and that you reference the full 'path' of the variable in the conditional statement (ex. SectionName.VariableName)
Conditional statements can refer to variables that are embedded in other forms. In this case a similar rule applies as above, i.e. the form itself needs to be assigned a variable and that form needs to reside in the correct 'space'. You will also need to tweak the formula
for check boxes: instead of FormName.SectionName.QuestionName[1]==true you need to write FormName.SectionName.QuestionName.values[1]==true
for multiple choice: instead of FormName.Section.Name.QuestionName.index==2 you need to writeFormName.Section.Name.QuestionName.index=="text of the option goes here"
Combining conditions
You can easily combine conditions into complex statements using the wizard.
For example, if you would like to combine two conditions, where both have to be true at the same time, choose "All" option:
This example reads "show the current widget when the person is a UK resident and owns a home"
If, instead, you would like any of the conditions to be true, choose "Any" option:
This example reads "show the current widget when the person is a UK or a US resident"
You can also create more complex structures that are embedded or grouped:
This example above reads "show the current widget when the person is a home owner or has high net worth and is either a UK or a US resident".