Logic
Logic decides where a respondent goes next. Without rules, a form shows its pages in order and ends on the first end page. A rule can send the respondent to another question or to an end page, depending on answers, hidden fields and variables.
Rules are kept in logic. The same list also holds the calculations that change variables. Logic is available from the Essential plan up.
Rule blocks
Section titled “Rule blocks”logic is a list of blocks. A block belongs to one question and holds all rules of that question.
| Key | Type | Description |
|---|---|---|
type | string | component for the rules of a question. hidden for the one block that runs when the form starts. See Rules at the start. |
ref | string | ref of the question that owns the rules. For a question in a group, the ref of that question, not of the group. Empty for the hidden block. |
actions | array | The rules: jumps and calculations in one list. |
A question has at most one block.
Actions
Section titled “Actions”Each item of actions has three keys.
| Key | Type | Description |
|---|---|---|
action | string | jump moves the respondent. add, subtract, multiply and divide change a variable and are described in Variables and scoring. |
condition | object | When the action applies. See Conditions. |
details | object | What the action does. |
There are no other actions. In particular, a rule cannot hide a question: to skip questions, jump over them.
details.to names the target.
to.type | to.value | Result |
|---|---|---|
component | ref of a question | The respondent goes to that question. When the question is in a group, they go to the page of the group. |
end_page | ref of an end page | The response is submitted and that end page is shown. |
{ "type": "component", "ref": "c3a9e1b7-5f24-4d68-8e0b-1a7c6d9f2e53", "actions": [ { "action": "jump", "condition": { "op": "is", "vars": [ { "type": "component", "value": "c3a9e1b7-5f24-4d68-8e0b-1a7c6d9f2e53" }, { "type": "choice", "value": "5d2f8c41-9b7e-4a13-a6c0-2e4f6b8d0a17" } ] }, "details": { "to": { "type": "end_page", "value": "c41d7a90-2e6b-4b35-9f08-6a1c3e5d7b92" } } }, { "action": "jump", "condition": { "op": "always", "vars": [] }, "details": { "to": { "type": "component", "value": "9d0b2c4e-6a81-4f37-b5c9-0e2a4c6f8b13" } } } ]}This block reads: when the respondent picks the first option, finish on the given end page. In all other cases, go to the given question.
Conditions
Section titled “Conditions”A condition has an operator in op and its operands in vars. There are three forms.
| Form | Shape |
|---|---|
| Always | { "op": "always", "vars": [] } |
| Comparison | { "op": "<operator>", "vars": [ <left>, <right> ] } |
| Group | { "op": "and" } or { "op": "or" } with a list of conditions in vars |
Operands
Section titled “Operands”The left operand is the thing being tested.
| Left operand | Tests |
|---|---|
{ "type": "component", "value": "<question ref>" } | The answer to a question. |
{ "type": "hidden", "value": "<name>" } | A hidden field. |
{ "type": "variable", "value": "<name>" } | A variable. |
The right operand is what it is compared with.
| Right operand | Used for |
|---|---|
{ "type": "choice", "value": "<option ref>" } | An option of the question on the left. |
{ "type": "constant", "value": … } | A text, a number, true or false, or a date as YYYY-MM-DD. |
Operators
Section titled “Operators”| Family | Operators | Right operand |
|---|---|---|
| Text | equal, not_equal, starts_with, ends_with, contains, not_contains | Text. |
| Choice | is, is_not | An option. |
| Yes or no | is, is_not | true or false. |
| Number | equal, not_equal, lower_than, lower_equal_than, greater_than, greater_equal_than | A number. |
| Date | on, not_on, earlier_than, earlier_than_or_on, later_than, later_than_or_on | A date. |
| Answered | answered | true. |
Text comparisons are case-sensitive. A comparison with a question that has no answer is false, also for the negative operators not_equal and is_not.
Operators by source
Section titled “Operators by source”| Source | Family |
|---|---|
text, mail, website, dropdown | Text. For a dropdown, the right operand is the label of the option. |
multiple_choice, picture_choice | Choice. With multiple selection, is is true when the option is among the picked ones. |
yesno, legal | Yes or no. |
number, rating, customer_sat, opinion_scale | Number. |
date | Date. |
file_upload, signature | Answered. |
| Hidden field | Text. |
| Variable | Number. |
The answers of phone_number, matrix, ranking, slider, numbers_scale, constant_sum and semantic_differential questions cannot be tested. These questions can still own rules that test other things, and they can be the target of a jump.
A rule of a question can test that question and the questions before it, every hidden field and every variable. It cannot test a later question.
Groups
Section titled “Groups”and and or combine conditions. The editor shows a flat list, “A and B or C and D”, and stores it with and binding tighter than or:
{ "op": "or", "vars": [ { "op": "and", "vars": [ { "op": "equal", "vars": [ … ] }, { "op": "equal", "vars": [ … ] } ] }, { "op": "and", "vars": [ { "op": "equal", "vars": [ … ] }, { "op": "equal", "vars": [ … ] } ] } ]}How rules run
Section titled “How rules run”- Rules run when the respondent leaves a page.
- Calculations of the page are applied first. A jump on the same page can therefore test a variable the page has just changed.
- Jumps are checked in the order of
actions. The first jump whose condition is true wins. The editor stores the “in all other cases” jump last. - On a group page, the rules of each question in the group are checked in order, and again the first true jump wins.
- A jump to a target that no longer exists is ignored.
- Without a matching jump the respondent goes to the next page, or, after the last page, to the first end page.
A jump can point backwards. The respondent then answers the earlier pages again, and the calculations of the pages after the target are dropped.
Rules at the start
Section titled “Rules at the start”One block can have the type hidden. It runs once, when the form starts, and can test hidden fields. Use it to route respondents by a value in the link:
{ "type": "hidden", "ref": "", "actions": [ { "action": "jump", "condition": { "op": "equal", "vars": [ { "type": "hidden", "value": "plan" }, { "type": "constant", "value": "pro" } ] }, "details": { "to": { "type": "component", "value": "9d0b2c4e-6a81-4f37-b5c9-0e2a4c6f8b13" } } } ]}A jump to a question opens the form on that page. A jump to an end page submits the response at once and shows the end page. A/B testing uses this block with the hidden field ab_testing.
Related
Section titled “Related”- Quotas send a respondent elsewhere when an option has reached its limit.
- Randomization changes the page order. Jumps follow the order the respondent sees.