up:form:switch
DOM event
When an [up-switch] field changes, this event is emitted on all dependent elements.
You can listen to up:form:switch to implement custom switching effects.
Event targets
This event is not emitted on the switching field. Instead each element matching the switch selector will receive an up:form:switch event:
<!-- Switching field won't receive an event on change -->
<select name="role" up-switch=".role-dependent">
<option value="trainee">Trainee</option>
<option value="manager">Manager</option>
</select>
<!-- Dependent field will receive up:form:switch -->
<input class="role-dependent" name="department">
<!-- Dependent field will receive up:form:switch -->
<input class="role-dependent" name="budget">
Timing
The up:form:switch is emitted at the following times:
- when the switching field is initially rendered.
- after a switching field has changed its value.
- after a switching checkbox was checked or unchecked.
- when a new selector match enters the form.
- when a kept
[up-switch]field is transported to a new form.
Event properties
event.target
required
The dependent element matching the [up-switch] selector.
If multiple elements match the selector, this event is emitted once for each match.
Type: Element
event.field
event.fieldTokens
required
An array describing the state of the controlling [up-switch] field.
The array contains:
- The field's value.
- A pseudo-value
:blankor:present, depending on the field's value. - For checkboxes, a pseudo-value
:checkedor:unchecked.
Type: Array<string>