A switch-case construction. Checks various conditions sequentially and executes the code from the result property when the corresponding condition is true.

You can use it to perform an action or display an additional interface element only when a certain condition is met.

View example

This helper is similar to a series of If...Then...Else logical expressions, so it is useful if there are more than two conditions for sequential verification. If you need to check one or two conditions, use the helper.if component.

How the helper works:

  1. The helper checks (conditions) from the array of cases objects, starting from the first one.
  2. If the condition is true (returns true), the helper returns the result (block of code) specified in the result property for the condition object in the cases array. The helper quits and subsequent conditions are not checked.
  3. If the condition is false (returns false), the helper checks the subsequent condition.
  4. If all conditions are false as a result of all checks, the helper returns the value specified in the default property (if it is not defined, the helper returns nothing).

Component properties

type*"helper.switch"Set component type.
cases*arrayAn array of objects consisting of condition and result property pairs.
cases[]objectObject parameters.
cases[].condition*conditionCondition to check.
cases[].result*anyThe element that is returned if the condition from the condition property is true (returns true).
defaultanyElement that is returned if none of the checked conditions returned true.
Contact support

Last updated: March 29, 2023

Getting started
Important tips
Useful recommendations
Working with Toloka
Project analysis
Toloka settings
Task interface
Template Builder
HTML/CSS/JS editor
Help and support