Class Switch

Switch

A UI element that supports being toggled on or off. This can only be used within a KeyValue widget.


 var switchKeyValue = CardService.newKeyValue()
     .setTopLabel("Switch key value widget label")
     .setContent("This is a key value widget with a switch on the right")
     .setSwitch(CardService.newSwitch()
         .setFieldName("form_input_switch_key")
         .setValue("form_input_switch_value")
         .setOnChangeAction(CardService.newAction()
             .setFunctionName("handleSwitchChange")));
 

Methods

MethodReturn typeBrief description
setFieldName(fieldName)SwitchSets the key that identifies this switch in the event object that is generated when there is a UI interaction.
setOnChangeAction(action)SwitchSets the action to take when the switch is toggled.
setSelected(selected)SwitchSets whether this switch should start as selected or unselected.
setValue(value)SwitchSets the value that is sent as the form input when this switch is toggled on.

Detailed documentation

setFieldName(fieldName)

Sets the key that identifies this switch in the event object that is generated when there is a UI interaction. Not visible to the user. Required, must be unique.

Parameters

NameTypeDescription
fieldNameStringthe key that is used to identify this switch.

Return

Switch — this object, for chaining.


setOnChangeAction(action)

Sets the action to take when the switch is toggled.

Parameters

NameTypeDescription
actionActionthe action to take when the switch is toggled.

Return

Switch — this object, for chaining.


setSelected(selected)

Sets whether this switch should start as selected or unselected.

Parameters

NameTypeDescription
selectedBooleanthe starting switch state setting.

Return

Switch — this object, for chaining.


setValue(value)

Sets the value that is sent as the form input when this switch is toggled on.

Parameters

NameTypeDescription
valueStringthe value associated with the name when the switch is on. When this is sent to the form callback, it is always represented as a string.

Return

Switch — this object, for chaining.

Send feedback about...

Apps Script
Apps Script