The Switch component for Retool Apps
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.
disabled
Whether input, interaction, selection, or triggering is disabled.
Type | boolean | ||||||
Format | True/False | ||||||
Mutability |
| ||||||
Default |
|
Examples
true
id
The unique identifier (name).
Type | string | ||||
Format | Plain Text | ||||
Mutability |
| ||||
Default |
|
Examples
query1
button1
isHiddenOnDesktop
Whether to show or hide this object in the desktop layout.
Type | boolean | ||||
Format | True/False | ||||
Mutability |
| ||||
Default |
|
Examples
true
isHiddenOnMobile
Whether to show or hide this object in the mobile layout.
Type | boolean | ||||
Format | True/False | ||||
Mutability |
| ||||
Default |
|
Examples
true
labelPosition
The position of the label relative to the input field or value.
Type | string | |||||||||
Format | Plain Text | |||||||||
Mutability |
| |||||||||
Allowed Values |
| |||||||||
Default |
|
Examples
top
maintainSpaceWhenHidden
Whether to take up space on the canvas if hidden
is true
.
Type | boolean | ||||
Format | True/False | ||||
Mutability |
| ||||
Default |
|
Examples
true
margin
The amount of margin to render outside.
Type | string | |||||||||
Format | Plain Text | |||||||||
Mutability |
| |||||||||
Allowed Values |
| |||||||||
Default |
|
Examples
4px 8px
required
Whether a value is required to be selected.
Type | boolean | ||||
Format | True/False | ||||
Mutability |
| ||||
Default |
|
Examples
true
showInEditor
Whether the component remains visible in the editor if hidden
is true
.
Type | boolean | ||||
Format | True/False | ||||
Mutability |
| ||||
Default |
|
Examples
true
style
Custom style options.
Type | object | ||||
Mutability |
|
tooltipText
The tooltip text to display next to the label on hover.
Type | string | ||||
Format | Markdown | ||||
Mutability |
| ||||
Default |
|
Examples
Submit
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()
Examples
Clear the validation message from switch
.
switch.clearValidation();
switch.clearValue()
Examples
Clear the current value of switch
.
switch.clearValue();
switch.focus()
Examples
Set focus on switch
.
switch.focus();
switch.resetValue()
Examples
Reset the current value of switch
.
switch.resetValue();
switch.scrollIntoView()
Scrolls the canvas or parent container so that the selected component appears in the visible area.
switch.scrollIntoView(options)
Parameters
Object Properties
behavior
The scroll behavior.
Type | string | ||||||
Allowed Values |
|
block
The scroll position relative to the component.
Type | string | ||||||||||
Allowed Values |
|
Examples
Scroll the minimum amount to immediately bring switch
into view.
switch.scrollIntoView({behavior: 'auto', block: 'nearest'});
switch.setDisabled()
Set the disabled
value to toggle whether the input field is disabled. Defaults to true
without a parameter.
switch.setDisabled(disabled)
Parameters
disabled
Whether input, interaction, selection, or triggering is disabled.
Type | boolean |
Format | True/False |
Default |
|
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.
switch.setHidden(hidden)
Parameters
Examples
true
Examples
Hide switch
.
switch.setHidden(true);
Unhide switch
.
switch.setHidden(false);
switch.setValue(value)
Examples
Set the current value of switch
to userValue
.
switch.setValue(userValue);
switch.toggle()
Examples
Toggle the current value of switch
.
switch.toggle();
Events
Events triggered by user interactions. You can configure event handlers in the IDE to trigger queries or other actions in response to events.
Event | Description |
---|---|
Change | The value is changed. |
False | The value is set to false . |
True | The value is set to true . |