Toggle is a boolean input rendered as a switch-style control. Use it for settings and immediate on/off state.
Contract¶
| Property | Type | Notes |
|---|---|---|
label |
str |
Text shown next to the control. |
checked |
bool |
Current boolean state. Supports literal, store binding, and data-model binding. |
action |
str or action object |
Optional action emitted on change. Action objects can include confirm. |
params |
dict |
Optional action context. |
Value collected by actions: bool.
Action Confirmation¶
Use an action object with confirm to require confirmation before the toggle change action is dispatched. If the user cancels the dialog, no backend action is sent and the toggle keeps its previous state.
The component test page exposes a toggle action counter and the last received payload so dispatch can be checked directly after confirming.
field = sdk.ui.Toggle(
"confirm_python_toggle",
sdk.i18n.t("components.toggle.confirm.python_label"),
checked=False,
)
field.set_prop(
"action",
{
"name": "components.toggle_confirm_action",
"context": {"source": "python_toggle"},
"confirm": {
"text": sdk.i18n.t("components.toggle.confirm.prompt"),
"confirm_text": sdk.i18n.t("components.toggle.confirm.accept"),
"cancel_text": sdk.i18n.t("components.toggle.confirm.cancel"),
},
},
)- kind: Toggle
id: confirm_yaml_toggle
label: "@t/components.toggle.confirm.yaml_label"
checked: false
action:
name: components.toggle_confirm_action
context:
source: yaml_toggle
confirm:
text: "@t/components.toggle.confirm.prompt"
confirm_text: "@t/components.toggle.confirm.accept"
cancel_text: "@t/components.toggle.confirm.cancel"Example¶
field = sdk.ui.Toggle(
"components_test_forms_toggle_store",
"Toggle",
checked=bound.store("/components_test/forms/toggle/store", scope="page", default=False),
)- kind: Toggle
id: components_test_forms_yaml_toggle
label: "Toggle YAML"
checked: {type: store, scope: page, path: /components_test/forms/toggle/store, default: false}Runtime¶
Use collect_input_ids to read true or false. Use checked.set property updates, stateUpdate, or dataModelUpdate to change the value from an action.