5.1 Rules (branching/skip formulas)
Rules are set in the top Form element. They determine which parts of the form will be shown to the user, depending on the selection the user does.
Add a skip rule
In order to create a rule, you must first create the elements you want to use in that rule. When that is done, the rule is defined in the Form element. In these pictures we show a medical report where we have created the questions Gender and Pregnant. We have checked the property Hidden as default for the Pregnant element, as we want to only show this question to female respondents.
- Click on the Form element at the top so this is selected.
- Go to the Rules tab in the Element Properties, and press [Add] to add a new rule.
- In the Zegeba Rule Editor, first write a name for the rule. We will call our rule Pregnant.
- Design the rule formula by first selecting an operator and dragging it to the left IF pane. Here we have chosen “=”:
- Then go to the Form Elements tab and drag the element you wish to specify the value of to the top yellow field of the operator. In our case this is Gender:
- Define in the left pane what you wish the value of the selected element to be compared to. We want the gender to be “female”, so we pull the [Text/String] operator to the left, below ‘=’, click and type in female. (Note that you should not drag the element “gender/female” to the IF box, but specify the value “Female” as a response to the gender question.)
- Then specify what should happen if the condition is fulfilled by dragging actions and form elements to the THEN DO pane. For our medical report we want to show females our question regarding pregnancy. From the tab Rule Logic we drag the action Show to the left.
Then we drag the element pregnant from the tab Form Elements into this.
Thus, our rule Pregnant defined in the top Form element makes the form show the question regarding pregnancy to only female respondents.
Note: The name of the rule is referenced in the Rules tab of the elements it mentions, in Related Rules. You can click on the rule here to access it.
Note: If you change the name of an element referenced in a rule, you will be asked if you would like to update the references to this element with the new name. If it is a simple name change, say “Yes”.
Sorting rules
From Zegeba v. 4.6, you can sort the rules listed in the Rules list.
- Hover the mouse over the list of rules to see the control icons to the right.
- Press the up arrow (^) or the down arrow (v) to move a rule up or down.
- Continue pressing the arrows until you are happy with the sequence of the rules.
Copying rules
Sometimes you need to create several rules that look similar but differ only for instance by the number of a row in a grid. From Zegeba v. 4.6, you can copy a rule to create one identical and then edit the copy – for instance by just changing the row listed to the next row below.
- Hover the mouse over the list of rules to see the control icons to the right.
- Press the copy icon (with the two sheets) to create a copy of the rule.
- The copy will have the name of the original + a number in brackets. Click on this to edit it. You can then change the name of the new rule and for instance click on the name of the grid row to get a list of the elements close by and select the row below.
Deactivating rules
From Zegeba v 4.8 you can deactivate a rule from inside the rules editor. This can be handy when you are testing how rules affect your form. Tick the box below “Name of Rule” to deactivate it.
Using tags to refer to multiple elements in a rule action
You can also use element tags as a property to mark the elements to be used in a rule. In the example pictured below, we had many text labels in two versions, English and French. All these have been tagged as either “English” or “French”. We then enter these tags in the show/hide rule:
Using tags means that you don’t have to enter every element ID, in this case all English and French labels, in the hide/show actions so it can save you a lot of time.
Tips: Tags can only be used in the Rule Action section, not the Rule Formula on top.
Formula tips
- To compare two values, first drag the Operator to the left pane, then the Form Elements and/or the Values.
- To compare with a specific value, use [Text / String] to enter the value.
- To change comparison logic, element or value, click on the item in the left pane to select other items.
Note: The logic in Rules defined on the top Form element has an IF… THEN structure. The logic in Validations defined on individual elements has an IF NOT… THEN structure, as explained in Designing: 5.2 Calculation and validation.
See also Designing: 5.4 List of functions.