Skip to main content

Toggle Switch

The Toggle Switch component can be used for binary choices, such as turning a feature on/off or enabling/disabling a setting.

Properties​

Data​

PropertyDescriptionExpected Value
LabelThe text to be used as the label for the toggle switch.String (e.g., Enable notifications).
Default stateSets the default state (On/Off) when the app is loaded.Select On or Off, or click fx and enter a logical expression.

Events​

Event
Description
On changeTriggers when the toggle switch is turned on or off by the user, or with the toggle() CSA.
info

Check Action Reference docs to get the detailed information about all the Actions.

Component Specific Actions (CSA)​

Following actions of Toggle switch component can be controlled using the component specific actions(CSA):

Action
Description
How To Access
setValueSets the value of the toggle switch. Doesn't trigger the On change event.Employ a RunJS query (e.g., await components.toggleswitch1.setValue(true)) or trigger it using an event.
setLoadingToggles the loading state of the toggle switch.Employ a RunJS query (e.g., await components.toggleswitch1.setLoading(true)) or trigger it using an event.
setVisibilityChanges the visibility of the toggle switch.Employ a RunJS query (e.g., await components.toggleswitch1.setVisibility(true)) or trigger it using an event.
setDisableDisables or enables the toggle switch.Employ a RunJS query (e.g., await components.toggleswitch1.setDisable(true)) or trigger it using an event.
toggleToggles the current state of the toggle switch and triggers the On change event.Employ a RunJS query (e.g., await components.toggleswitch1.toggle()) or trigger it using an event.

Exposed Variables​

Variables
Description
How To Access
valueHolds the boolean value true if the toggle switch is checked and false if unchecked.Accessible dynamically with JS (e.g., {{components.toggleswitch1.value}}).
labelThe text label of the toggle switch.Accessible dynamically with JS (e.g., {{components.toggleswitch1.label}}).
isValidIndicates if the toggle switch state is valid.Accessible dynamically with JS (e.g., {{components.toggleswitch1.isValid}}).
isMandatoryIndicates if the toggle switch is mandatory.Accessible dynamically with JS (e.g., {{components.toggleswitch1.isMandatory}}).
isLoadingIndicates if the toggle switch is in a loading state.Accessible dynamically with JS (e.g., {{components.toggleswitch1.isLoading}}).
isVisibleIndicates if the toggle switch is visible.Accessible dynamically with JS (e.g., {{components.toggleswitch1.isVisible}}).
isDisabledIndicates if the toggle switch is disabled.Accessible dynamically with JS (e.g., {{components.toggleswitch1.isDisabled}}).

Validation​

Validation Option
Description
Expected Value
Make this field mandatoryDisplays a 'Field cannot be empty' message if the switch is off.Enable/disable the toggle button or dynamically configure the value by clicking on fx and entering a logical expression.
Custom validationSpecifies a validation error message for specific conditions.Logical Expression (e.g., {{components.toggleswitch1.value === false &&"Value needs to be checked"}}).

To add regex inside Custom Validation, you can use the below format:

Format: {{(<regexPattern>.test(<value>)) ? '' : 'Error message';}}

Example: {{(/^\d{1,10}$/.test(components.textinput1.value)) ? '' : 'Error message';}}

Additional Actions​

Action
Description
Configuration Options
Loading stateEnables a loading spinner, often used with the isLoading property to indicate progress. Toggle or set dynamically.Enable/disable the toggle button or dynamically configure the value by clicking on fx and entering a logical expression.
VisibilityControls component visibility. Toggle or set dynamically.Enable/disable the toggle button or dynamically configure the value by clicking on fx and entering a logical expression.
Collapse when hiddenCollapses the component's space when it is hidden, so surrounding components fill the space. Takes effect when the app runs (preview or released app), not on the editor canvas.Enable/disable the toggle button or dynamically configure the value by clicking on fx and entering a logical expression.
DisableEnables or disables the component. Toggle or set dynamically.Enable/disable the toggle button or dynamically configure the value by clicking on fx and entering a logical expression.
TooltipProvides additional information on hover. Supports Plain text, Markdown, and HTML formats.String (e.g., Are you a registered user? ).

Devices​

Property
Description
Expected Value
Show on desktopMakes the component visible in desktop view.You can set it with the toggle button or dynamically configure the value by clicking on fx and entering a logical expression.
Show on mobileMakes the component visible in mobile view.You can set it with the toggle button or dynamically configure the value by clicking on fx and entering a logical expression.

Styles

Label​

Label Property
Description
Configuration Options
Text colorSets the color of the component's label.Select the color or click on fx and input code that programmatically returns a Hex color code.
AlignmentSets the position of the label and input field.Click on the toggle options or click on fx to input code that programmatically returns an alignment value - left or right.

Switch​

Label Property
Description
Configuration Options
Border colorSets the border color of the switch.Select the color or click on fx and input code that programmatically returns a Hex color code.
Checked colorSets the color of the toggle switch when it is checked.Select the color or click on fx and input code that programmatically returns a Hex color code.
Unchecked colorSets the color of the toggle switch when it is not checked.Select the color or click on fx and input code that programmatically returns a Hex color code.
Handle colorSets the color of the switch handle (knob).Select the color or click on fx and input code that programmatically returns a Hex color code.
Box shadowSets the box shadow properties of the component.Select the box shadow color and adjust the related properties or set it programmatically using fx.
PaddingSets the padding around the component. Default adds 2px of padding; None removes it.Choose Default or None.

Advanced​

Property
Description
Configuration Options
CSS classAdds a custom CSS class to the component, which can be targeted using Custom Styles for advanced styling.Enter one or more class names.
info

The Advanced section is available only if your plan has the Custom Styles feature enabled.