Logic Jumps
This walkthrough will help you use Logic Jumps when you’re creating or updating a form with the Create API.
If you’re not familiar with Typeform’s Logic Jump concept, this Help Center article is a great introduction to the basics. Some Logic Jump capabilities rely on Hidden Fields, so it’s a good idea to get to know Hidden Fields too.
Here’s an example Logic Jump:
The three main parts of this Logic Jump are the type and ref definitions, the to object, and the condition object. Here’s how they work together in a Logic Jump:
- The
typeandrefdefinitions identify which field triggers the Logic Jump. - The
toobject identifies which field or screen the Logic Jump leads to. - The
conditionobject sets the conditions for executing the Logic Jump.
Let’s look at each of the three parts in detail.
Part 1: type and ref definitions
The type and ref definitions identify the field that triggers the Logic Jump. This part answers the question, “Where from?”
Logic Jumps can be triggered by the answer to a question or by a hidden field value. You can jump from a field based on an answer or jump to a field or skip fields based on a Hidden Field value. Both types of Logic Jumps must include the actions array, which will contain the other two parts of the Logic Jump (the to and condition objects).
A Logic Jump triggered by the answer to a question includes type and ref definitions, in addition to the actions array:
A Logic Jump triggered by a Hidden Field value only includes a type definition and the actions array:
Here’s a description of each element in the type and ref definitions:
Logic Jump definitions are unique per triggering field. Per form, there should be at most one Logic Jump definition with "type": "hidden" and at most one Logic Jump definition for each field ("type": "field"). Multiple jump conditions can be defined inside the actions array.
For example, this is not valid, because it has two Logic Jump definitions for the field ref_trigger_field:
In this case, the correct format should be to merge actions from the two definitions of field ref_trigger_field into a single one:
Part 2: The to object
The to object defines where the Logic Jump leads to — it answers the question, “Where to?” You have three options: a field in the form, the default thank-you screen, or a custom thank-you screen.
Here’s an example object for a Logic Jump to a field in the form:
And for a jump to the default thank-you screen:
And for a jump to a custom thank-you screen:
Here’s a description of each element in this to object:
You can use Logic Jumps for more than jumping to a question! If your form adds up the prices of different items or keeps a score and provides a total at the end, use target and value instead of to.
The POST https://api.typeform.com/forms endpoint includes a schema explanation.
Part 3: The condition object
In the condition object, you specify the conditions for executing your Logic Jump. The conditions answer the question, “Under what circumstances?” The condition object is the IF statement in your Logic Jump.
In plain language, a condition would be something like “Execute the jump if the numeric answer for Question X is less than 5” or “Execute the jump if the person answers “No” to the legal agreement.” In code, it looks quite different!
In our example, the Logic Jump should execute when a respondent answers “10” in the field with the ref “readable field reference”.
Here’s a description of each element in the condition object:
Read on for details about the operators (op) you can use for each field type.
All fields
Example:
For the always operator, you don’t need to specify any vars. Your typeform will always execute this Logic Jump.
Text fields (short text, long text, dropdown, email, website)
Example: Execute jump if text field answer matches specified value
Numeric fields (rating, opinion scale, number)
For conditions based on numeric fields, the specified value must be an integer.
Example: Execute jump if numeric answer is less than the specified value
Choice fields (text choice, picture choice, yes/no, legal)
Example: Execute jump if picture choice or text choice answer matches the ref of the choice
Example: Execute jump if yes/no or legal answer matches specified Boolean value
Date field
Example: Execute jump if date field matches specified value
The date format is YYYY-MM-DD.
File upload field
Example:
Hidden Field
Example: Execute jump if referrer is “facebook”
Best Practices for Logic Jumps
Follow these best practices to create Logic Jumps that work beautifully.
Use ref values that actually exist
This is the most important part of ensuring that your Logic Jumps work properly. Make sure that you don’t include a ref to a field that doesn’t exist in the typeform. And as always, watch for typos!
Place conditions in the correct order
If you include more than one condition in a Logic Jump, it’s important to put the conditions in the correct order so that the Logic Jump executes the way you want. The first condition that’s met will trigger the Logic Jump, and any subsequent conditions will be ignored.
For example, suppose you have multiple choice question, and respondents can pick more than one answer. If the answer is Mango, the form should skip to Question 3. If the answer is Mango and Apple, the form should skip to question 4.
For this Logic Jump to work properly, put the condition “If [Mango AND Apple], jump to Question 4” first—before the condition “If [Mango], jump to Question 3.”
Here’s what this looks like in code:
If you put “If [Mango], skip to Question 3” first, and a respondent answered [Mango AND Apple], the Logic Jump to Question 3 would execute because the answer contains “Mango.”
Place your most restrictive conditions first
When you’re organizing the order of your Logic Jumps, place your most restrictive conditions first, followed by your more general conditions.
For example, if you have the conditions “answer begins with b” and “answer is boat”, place the condition “answer is boat” first because it’s more restrictive.
Use AND and OR operators correctly
You can use AND and OR operators to add several conditions to a single Logic Jump, but it’s important to use the correct operators in the correct order to achieve the result you want.
Imagine that this is Question 1: “Select your favorite fruits.” The answer choices are Apple, Orange, and Mango. Respondents can select one, two, or all three choices.
Here’s what the Logic Jump code should look like for the scenario IF answer is [Apple AND Orange] OR [Mango], jump to Question 3:
And here’s what the Logic Jump code should look like for the scenario IF answer is [Apple AND Orange] OR [Apple AND Mango], jump to Question 3:
Avoid sending respondents back to a question that they haven’t visited
Logic Jumps can only jump to a previous question if the respondent has already visited that question. So for example, if a respondent bypassed Question A in Logic Jump X, you can’t send the respondent back to Question A in Logic Jump Y. Place the question or statement that a Logic Jump leads to after the question that triggers the Logic Jump.
Multi-branching
Multi-branching allows you to ask follow-up questions based on answers to a previous question. For example, if a respondent answers the multiple-choice question, “Which book do you prefer? A. Charlotte’s Web B. James and the Giant Peach” by selecting Charlotte’s Web, you can create multi-branch Logic Jumps to ask follow-up questions specific to Charlotte’s Web and skip questions related to James and the Giant Peach. Here are some best practices for multi-branching.
Define a Logic Jump at the beginning of each branch
The question that comes before a branch must be a Logic Jump. If you forget to include a Logic Jump before a branch, respondents could end up in a branch of questions that don’t make sense based on their previous answers.
For example, if you forget to include a Logic Jump on the multiple-choice question, “Which book do you prefer? A. Charlotte’s Web B. James and the Giant Peach”, respondents who answer “A. Charlotte’s Web” will still see questions about James and the Giant Peach.
Include follow-up questions for all possible answers to the “trigger” question
Make sure that your Logic Jumps include follow-up questions for all the possible answers (or combinations of answers). To continue our “Which book do you prefer?” example, you’d need two branches: one for the answer A. Charlotte’s Web and one for the answer B. James and the Giant Peach. If you offer a third answer choice, C. Watership Down, you’d need a third branch in case respondents choose answer C.
Now, consider how many branches you’d need for the question, “Which of these books do you enjoy? A. Charlotte’s Web B. James and the Giant Peach”. For this question, respondents could choose only A., only B., both A. and B., or neither A. or B. So you’d need four branches.
Include as many Logic Jumps as you need
There’s no limit to the number of Logic Jumps you can include — here’s an example typeform that uses more than 100! As long as your Logic Jumps are set up properly, you can use as many as you need to give your respondents a great experience.
What’s next?
Learn more about how Hidden Fields work in the Create API. Or, check out the Create reference for endpoints.