Skip to main content

The Switch component for Retool Apps

An input field to toggle a boolean value.

Settings

Switch includes the following configurable options when building apps in the IDE.

Custom ruleDisabledEvent handlersForm data keyHide validation messageShow on desktopShow on mobileLabelAlignmentLabelsPositionAllow wrappingMaintain space when hiddenMarginRequiredAlways show in edit modeStylesHelper textValue

Properties

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

The custom validation message to display if the invalid is true.


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


events

object[]

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

Properties

event

enum

The event type. Refer to the events section for a list of supported events.


method

enum

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


The type of action to perform.

Values
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).



The key used by a Form component to assign default values to input fields using form.initialData, and to construct the form.data property.


global

boolean

Whether the object is globally scoped for use in all app pages.


boolean

Whether the component is visible.


Whether to hide the validation message if the invalid is true.


id

string

The unique identifier.


invalid

boolean

Whether the value has failed any validation rules.


Whether the component is visible in the desktop layout.


Whether the component is visible in the mobile layout.


label

string

The text label to display.


The horizontal alignment of the label.

Values
left

Left of the input field.

top

Above the input field.


The label for the node.


The position of the label relative to the input field or value.

Values
top

Above the input field or value.

left

Left of the input field or value.


Whether the label can wrap to multiple lines.


Whether the component takes up space on the canvas if hidden is true.


The amount of margin to render outside.

Values
4px 8px

Normal margin.

0

No margin.


pluginType

string

The plugin type.


Whether a value is required.


Whether to remain visible in the editor if hidden is true.


style

object

Custom style options in use. Not all style options may be available for all components.


The tooltip text to display.


validationMessage

string

The validation message to display if invalid is true.


value

boolean

The value.


Methods

JavaScript API methods for interacting with Switch. You can write JavaScript almost anywhere in Retool and use methods to manipulate data and property values.

clearValidation

Clear the validation message from the input field.

switch.clearValidation()

clearValue

Clear the current values.

switch.clearValue()

focus

Set focus on the input field.

switch.focus()

resetValue

Reset the current value to the default value.

switch.resetValue()

scrollIntoView

Scrolls the canvas or parent container so that the selected component appears in the visible area.

switch.scrollIntoView(scrollIntoViewOptions)
Parameters

scrollIntoViewOptions

object

The scroll options.

Properties

behavior

enum

The scroll behavior.

Values
auto

Scroll immediately to the specified position.

smooth

Scroll gradually to the specified position.


block

enum

The scroll position relative to the component.

Values
nearest

Scrolls only the minimum amount required for the component to appear in the visible area. Scrolling does not occur if the component is already in view.

start

Scrolls to position the component at the top of the visible area.

center

Scrolls to position the component in the middle of the visible area.

end

Scrolls to position the component at the bottom of the visible area.




setDisabled

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

switch.setDisabled(disabled)
Parameters

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



setHidden

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

switch.setHidden(hidden)
Parameters

boolean

Whether the component is visible.



setValue

Set the current value.

switch.setValue(value)
Parameters

The value.



toggle

Toggle the current value between true and false

switch.toggle()

Events

Events are triggered by user interactions, such as clicking a button or entering a value. Use event handlers to trigger queries or other actions in response to events.

change

The value is changed.


false

The value is set to false.


true

The value is set to true.