Switch
What is the Form Switch?
The Switch form type is an on/off toggle. Tapping it flips between the on (active) and off (inactive) states, and the field stores a boolean value.
Options
Active Color
- The color of the toggle when it is on (active).
- Default:
#00a5fe.
Inactive Color
- The color of the toggle when it is off (inactive).
- Default:
#004363.
Background Color
- The color of the track behind the toggle.
- Default:
transparent.
Active by default
- The initial state of the toggle when the field first renders, when no value is supplied by a datasource.
- Default:
false(off).
The switch does not have its own corner-rounding option. Its rounding follows the
border-radius applied to the widget's container through the general styling.
Setting Mock Field and Own Value
The Switch stores its value as a boolean (true for on, false for off). It updates the
Mock and Own values when:
- The widget is rendered (using the datasource value if present, otherwise the configured Active-by-default state).
- The toggle is tapped.
- An external message tells it to change, clear, or reset.
Each write also stores the activeColor, inactiveColor, backgroundColor, and default
properties.
Validation
The Switch does not validate itself.
Sensor Events
-
The Switch does not validate, so it does not send a
{FORM-NAME}-validevent. -
Whenever the value is written, the field broadcasts a sensor event named after the field, carrying the current boolean value:
{FORM-NAME} value: [true/false]This broadcast is suppressed when the change comes from a silent Clear or Reset.
External Messages
The Switch listens to the three basic external messages:
- Set Form: Reads the
valueparameter as a string."true"turns the toggle on (if it is currently off) and"false"turns it off (if it is currently on). Any other value is ignored. - Clear Form: Turns the toggle off if it is currently on. If it is already off, nothing happens.
- Reset Form: Restores the toggle to its configured Active-by-default state.
The silent variants of Clear and Reset do the same but suppress the {FORM-NAME} sensor event.
Value from Datasource
- The Switch does not build its content from an external (bound) datasource array.
- On mount, if the bound form output datasource already holds a value for this field, the toggle is initialized to that boolean state instead of the configured Active-by-default state.