Skip to main content

The Switch component for Retool Mobile

An input field to toggle a boolean value.

Properties

All properties for this object with supported data types or values. You can write JavaScript almost anywhere in Retool to manipulate or read property values.

caption

The additional text to display with the label.

Type string
Format Plain Text
Configurability Inspector > Content > Add-ons > Label > Caption
Defaultnull

disabled

Whether input, interaction, selection, or triggering is disabled.

Type boolean
Format True/False
Configurability Inspector > Interaction > Disabled
Defaultfalse
Examples
true

events

A list of configured event handlers that trigger actions or queries.

Type array
Array values object
Configurability Inspector > Interaction > Event handlers
Defaultnull
Array Object Properties

event

The event that triggers the action. Refer to the events section for details of available events for this object.

Type string
Configurability Inspector > Interaction > Event handlers > Event
Defaultnull

method

The JavaScript method to perform when type is datasource, widget, state, or localStorage.

Type string
Configurability Inspector > Interaction > Event handlers > Edit event handler > Run script actions
Defaultnull

type

The type of action to perform.

Type string
Configurability Inspector > Interaction > Event handlers > Edit event handler > Action
Allowed Values
ValueDescription
datasource

Control query.

widget

Control component.

script

Run script.

state

Set variable.

localStorage

Set localStorage.

util

Perform utility action (e.g., Open URL or Confetti).

Defaultnull


hidden

Whether this object is hidden from view.

Type boolean
Format True/False
Configurability Inspector > Appearance > Hidden
Defaultfalse
Examples
true


type

The type of content or action to perform.

Type string
Configurability Inspector
Defaultnull

value

The current value or the default value.

Type boolean
Format True/False
Configurability Inspector > Content > Default value
Defaultfalse
Examples
true

width

The width.

Type string
Format Integer
Configurability Inspector
Allowed Values
ValueDescription
full

Full width.

fixed

Fixed width.

Defaultnull
Examples
1280

Methods

JavaScript API methods for this object. You can write JavaScript almost anywhere in Retool and use methods to manipulate data and property values.

switch.clearValidation()

Clear the validation message from the input field.

Definition
switch.clearValidation()
Examples

Clear the validation message from switch.

switch.clearValidation();

switch.clearValue()

Clear the current values.

Definition
switch.clearValue()
Examples

Clear the current value of switch.

switch.clearValue();

switch.focus()

Set focus on the input field.

Definition
switch.focus()
Examples

Set focus on switch.

switch.focus();

switch.resetValue()

Reset the current value to the default value.

Definition
switch.resetValue()
Examples

Reset the current value of switch.

switch.resetValue();

switch.setDisabled()

Set the disabled value to toggle whether the input field is disabled. Defaults to true without a parameter.

Definition
switch.setDisabled(disabled)
Parameters

disabled

Whether input, interaction, selection, or triggering is disabled.

Type boolean
Format True/False
Default
false
Examples
true

Examples

Disable switch.

switch.setDisabled(true);

Enable switch.

switch.setDisabled(false);

switch.setHidden()

Set the hidden value to toggle whether the component is visible. Defaults to true without a parameter.

Definition
switch.setHidden(hidden)
Parameters

hidden

Whether this object is hidden from view.

Type boolean
Format True/False
Default
false
Examples
true

Examples

Hide switch.

switch.setHidden(true);

Unhide switch.

switch.setHidden(false);

switch.setValue()

Sets the value of the checkbox.

Definition
switch.setValue(key, value)
Parameters

key

The key.

Type string

value

The value.

Type string | number | boolean | object | array

Examples

Set the current value of switch to userValue.

switch.setValue(userValue);

switch.toggle()

Toggle the current value between true and false.

Definition
switch.toggle()
Examples

Toggle the current value of switch.

switch.toggle();

switch.validate()

Validates the value of the input field.

Definition
switch.validate()
Examples

Validate the value of switch.

switch.validate();

Events

Events triggered by user interactions. You can configure event handlers in the IDE to trigger queries or other actions in response to events.

EventDescription
ChangeThe value is changed.
FalseThe value is set to false.
TrueThe value is set to true.