Skip to content

Conditional Logic ​

Conditional logic lets a survey react to the answers people give. You write simple rules in the form "if this answer is X, then do Y", for example:

  • If the house is an apartment, ask how many rooms it has.
  • If the land is vacant, skip the questions about the building.
  • If the building number is below 20, fill in "Abandoned" automatically.

Rules go in the conditionals section of the survey. Each rule gets its own number ("1", "2", "3" …) so you can tell them apart, and the rule itself is written as text:

json
"conditionals": {
  "1": "type_of_house == 'APARTMENT' >> room_count"
}

Every rule has two parts:

  1. The condition: the question to check and the answer to look for (type_of_house == 'APARTMENT').
  2. The action: what to do when that answer is given (>> room_count, which means "show the room count question").

A rule can do one of three things:

  • Show a question that is otherwise hidden
  • Hide a question that is otherwise shown
  • Fill in an answer automatically

Symbol Cheat Sheet ​

Rules use a few short symbols. You don't need to memorize them; come back to this table whenever you need to.

Actions (what to do) ​

SymbolRead it asExampleMeaning
>>"then show"age > 18 >> emailShow the email question for people over 18
!>"then hide"age < 18 !> emailHide the email question for people under 18
=>"then fill in"number < 20 => status = 'ABANDONED'Fill in "ABANDONED" as the status

Comparisons (checking an answer) ​

SymbolRead it asExample
=="is"color == 'RED': the color is red
!="is not"color != 'RED': the color is anything except red
>"is more than"age > 18: older than 18 (18 itself does not count)
>="is at least"age >= 18: 18 or older
<"is less than"age < 18: younger than 18 (18 itself does not count)
<="is at most"age <= 18: 18 or younger

Joining things together ​

SymbolRead it asExample
&&"and"age > 18 && city == 'LAGOS': both must be true
||"or"city == 'LAGOS' || city == 'ABUJA': either one is enough

Writing answers in a rule

Put text answers inside single quotes, exactly as they appear in the question's choices: 'APARTMENT', 'Vacant and Undeveloped'. Numbers don't need quotes: 18, 50000.

Skip Logic (Visibility) ​

Skip logic decides which questions a person sees. It keeps the survey short by only asking questions that apply to them.

  • Use >> for a question that should only appear in certain cases.
  • Use !> for a question that should appear for everyone except in certain cases.

Show Fields ​

A question used with >> is hidden at first. It appears only when the rule's condition is true.

Pattern: condition >> question_to_show

json
"7": "type_of_house == 'APARTMENT' >> room_count"

If the type of house is an apartment, show the room count question. For any other type of house, the question stays hidden.

json
"8": "age > 18 >> email"

If the person is older than 18, show the email question.

Hide Fields ​

A question used with !> is shown at first. It disappears when the rule's condition is true, so the person skips it.

Pattern: condition !> question_to_hide

json
"10": "age < 18 !> email"

Everyone sees the email question, unless they are younger than 18.

Show or hide?

Pick whichever reads more naturally. "Only ask about rent if the property is rented" suggests >>. "Ask about the building, unless the land is vacant" suggests !>.

Multiple Target Fields ​

One rule can show or hide several questions at once. List them after the symbol and join them with &&.

Pattern: condition !> question_a && question_b && question_c

json
"3": "land_use == 'Vacant and Undeveloped' !> property_structure && roof_type && num_rooms_units"

If the land is vacant and undeveloped, there is no building to describe, so hide the structure, roof type and number of rooms questions.

Set Logic (Auto-Assignment) ​

Set logic fills in an answer for the person, so they don't have to.

Pattern: condition => question = 'answer'

json
"4": "building_number < 20 => type_of_building = 'ABANDONED'"

If the building number is below 20, fill in "ABANDONED" as the type of building.

Complex Logic ​

Multiple Conditions (AND / OR) ​

A rule can check more than one answer. Wrap the conditions in brackets ( ) and join them with:

  • && (and): every condition must be true
  • || (or): at least one condition must be true
json
"6": "(building_age <= 5 && building_color == 'CREAM') => type_of_building = 'NEW'"

If the building is 5 years old or less and it is cream-colored, fill in "NEW" as the type of building. A cream building that is 10 years old would not match.

json
"9": "(income >= 50000 && employment_status != 'UNEMPLOYED') >> loan_eligibility"

If the income is at least 50,000 and the person is not unemployed, show the loan eligibility question.

Array Membership ​

To check whether an answer is any one of a list, put the options in square brackets [ ], separated by commas. This is shorter than writing several || conditions.

json
"5": "building_name == ['CALIFORNIA', 'SILICON VALLEY'] >> type_of_building"

If the building name is California or Silicon Valley, show the type of building question.

Action Chaining ​

One rule can do several things at once. Join the actions with &&.

Pattern: condition >> question_a && question_b = 'answer'

json
"5": "building_name == 'CALIFORNIA' >> type_of_building && building_color = 'GREEN'"

If the building name is California, show the type of building question and fill in "GREEN" as the building color.

Grouped Choices ​

Some questions have grouped choices: the person first picks a category (for example Agricultural), then a specific option inside it (for example Open market / stalls). The two answers are saved separately:

  • the category is saved under the question's key
  • the specific option is saved under its sub_key

Use key in a rule to react to a whole category, and sub_key to react to one specific option.

When choices are nested more than two levels deep, sub_key is a list with one key per level. Each level is saved under its own key, so a rule can react at any level:

json
// Anything in the North Central zone
"6": "zone == 'North Central' >> lga_office"

// Any LGA in Niger State
"7": "state == 'Niger' >> niger_permit_number"

// One LGA only
"8": "lga == 'Bida' >> bida_ward"
json
// Any option in the Agricultural or Transportation category
"4": "(land_use == 'Agricultural' || land_use == 'Transportation') >> roof_type"

// Only this one specific option
"5": "detail_land_use == 'Open market / stalls' >> num_rooms_units"

The answer in the rule must match the category or option name exactly, including capital letters and spaces.

Key Matching ​

A rule refers to questions by their key, the short name given to each question in the fields section. The name in the rule must be spelled exactly the same way, including capital and small letters. room_count, Room_Count and ROOM_COUNT count as three different names.

json
// The question
{ "key": "type_of_house", ... }

// The rule must use the same spelling
"7": "type_of_house == 'APARTMENT' >> room_count"

If a name doesn't match, the rule silently does nothing, so this is the first thing to check when a rule isn't working.