Switch
A control that allows the user to toggle between checked and not checked.
Requires JS
This component requires the switch_controller stimulus controller.
API Reference
Switch
| Name | Type | Default |
|---|---|---|
name: | string | nil |
value: | string | "1" |
| The value sent to the server when the switch is in the checked/on state. | ||
unchecked_value: | string | "0" |
| The value sent to the server when the switch is in the unchecked/off state. | ||
checked: | boolean | false |
| The initial state of the switch. | ||
include_hidden: | boolean | true |
| Whether to include a hidden field that ensures a value is sent even when the checkbox is unchecked. | ||
disabled: | boolean | false |
| When true, disables the switch and prevents user interaction while maintaining visual state. | ||
attributes | keyword arguments | |
Keyboard Interactions
| Key | Description |
|---|---|
| Space | Checks/unchecks the switch. |
| Enter | Checks/unchecks the switch. |
Examples
On This Page