Class sap.m.SwitchModule: sap/m/Switch

extends Control

A switch is a user interface control on mobile devices that is used for change between binary states. The user can also drag the button handle or tap to change the state.

Constructor Summary
new sap.m.Switch(sId?, mSettings?)Constructor for a new Switch.
Event Summary
change(oControlEvent)Triggered when a switch changes the state.
Events borrowed from class sap.ui.core.Control
Method Summary
sap.m.Switch.extend(sClassName, oClassInfo?, FNMetaImpl?)Creates a new subclass of class sap.m.Switch with name sClassName and enriches it with the information contained in oClassInfo.
sap.m.Switch.getMetadata()Returns a metadata object for class sap.m.Switch.
addAriaLabelledBy(vAriaLabelledBy)Adds some ariaLabelledBy into the association ariaLabelledBy.
attachChange(oData?, fnFunction, oListener?)Attaches event handler fnFunction to the change event of this sap.m.Switch.
detachChange(fnFunction, oListener)Detaches event handler fnFunction from the change event of this sap.m.Switch.
fireChange(mArguments?)Fires event change to attached listeners.
getAriaLabelledBy()Returns array of IDs of the elements which are the current targets of the association ariaLabelledBy.
getCustomTextOff()Gets current value of property customTextOff.
getCustomTextOn()Gets current value of property customTextOn.
getEnabled()Gets current value of property enabled.
getName()Gets current value of property name.
getState()Gets current value of property state.
getType()Gets current value of property type.
removeAllAriaLabelledBy()Removes all the controls in the association named ariaLabelledBy.
removeAriaLabelledBy(vAriaLabelledBy)Removes an ariaLabelledBy from the association named ariaLabelledBy.
setCustomTextOff(sCustomTextOff)Sets a new value for property customTextOff.
setCustomTextOn(sCustomTextOn)Sets a new value for property customTextOn.
setEnabled(bEnabled)Sets a new value for property enabled.
setName(sName)Sets a new value for property name.
setState(bState)Change the switch state between on and off.
setType(sType)Sets a new value for property type.
Constructor Detail
new sap.m.Switch(sId?, mSettings?)
Constructor for a new Switch.

Accepts an object literal mSettings that defines initial property values, aggregated and associated objects as well as event handlers. See sap.ui.base.ManagedObject for a general description of the syntax of the settings object.

The supported settings are:

  • Properties
  • Events
    • change : fnListenerFunction or [fnListenerFunction, oListenerObject] or [oData, fnListenerFunction, oListenerObject]

In addition, all settings applicable to the base type sap.ui.core.Control can be used as well.

Parameters:
{string}sId? id for the new control, generated automatically if no id is given
{object}mSettings? initial settings for the new control
Event Detail
change(oControlEvent)
Triggered when a switch changes the state.
Parameters:
{sap.ui.base.Event}oControlEvent
{sap.ui.base.EventProvider}oControlEvent.getSource
{object}oControlEvent.getParameters
{boolean}oControlEvent.getParameters.state The new state of the switch.
Method Detail
sap.m.Switch.extend(sClassName, oClassInfo?, FNMetaImpl?): function
Creates a new subclass of class sap.m.Switch with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.core.Control.extend.

Parameters:
{string}sClassName Name of the class being created
{object}oClassInfo? Object literal with information about the class
{function}FNMetaImpl? Constructor function for the metadata object; if not given, it defaults to sap.ui.core.ElementMetadata
Returns:
{function} Created class / constructor function
sap.m.Switch.getMetadata(): sap.ui.base.Metadata
Returns a metadata object for class sap.m.Switch.
Returns:
{sap.ui.base.Metadata} Metadata object describing this class
addAriaLabelledBy(vAriaLabelledBy): sap.m.Switch
Adds some ariaLabelledBy into the association ariaLabelledBy.
Parameters:
{string|sap.ui.core.Control}vAriaLabelledBy the ariaLabelledBy to add; if empty, nothing is inserted
Since:
1.27.0
Returns:
{sap.m.Switch} Reference to this in order to allow method chaining
attachChange(oData?, fnFunction, oListener?): sap.m.Switch
Attaches event handler fnFunction to the change event of this sap.m.Switch.

When called, the context of the event handler (its this) will be bound to oListener if specified, otherwise it will be bound to this sap.m.Switch itself.

Triggered when a switch changes the state.

Parameters:
{object}oData? An application-specific payload object that will be passed to the event handler along with the event object when firing the event
{function}fnFunction The function to be called when the event occurs
{object}oListener? Context object to call the event handler with. Defaults to this sap.m.Switch itself
Returns:
{sap.m.Switch} Reference to this in order to allow method chaining
detachChange(fnFunction, oListener): sap.m.Switch
Detaches event handler fnFunction from the change event of this sap.m.Switch.

The passed function and listener object must match the ones used for event registration.

Parameters:
{function}fnFunction The function to be called, when the event occurs
{object}oListener Context object on which the given function had to be called
Returns:
{sap.m.Switch} Reference to this in order to allow method chaining
fireChange(mArguments?): sap.m.Switch
Fires event change to attached listeners.

Expects the following event parameters:

  • state of type booleanThe new state of the switch.
Parameters:
{Map}mArguments? The arguments to pass along with the event
Returns:
{sap.m.Switch} Reference to this in order to allow method chaining
getAccessibilityInfo()
See:
{sap.ui.core.Control#getAccessibilityInfo}
getAriaLabelledBy(): sap.ui.core.Control[]
Returns array of IDs of the elements which are the current targets of the association ariaLabelledBy.
Since:
1.27.0
Returns:
{sap.ui.core.Control[]}
getCustomTextOff(): string
Gets current value of property customTextOff.

Custom text for the "OFF" state.

"OFF" translated to the current language is the default value. Beware that the given text will be cut off if available space is exceeded.

Default value is .

Returns:
{string} Value of property customTextOff
getCustomTextOn(): string
Gets current value of property customTextOn.

Custom text for the "ON" state.

"ON" translated to the current language is the default value. Beware that the given text will be cut off if available space is exceeded.

Default value is .

Returns:
{string} Value of property customTextOn
getEnabled(): boolean
Gets current value of property enabled.

Whether the switch is enabled.

Default value is true.

Returns:
{boolean} Value of property enabled
getName(): string
Gets current value of property name.

The name to be used in the HTML code for the switch (e.g. for HTML forms that send data to the server via submit).

Default value is .

Returns:
{string} Value of property name
getState(): boolean
Gets current value of property state.

A boolean value indicating whether the switch is on or off.

Default value is false.

Returns:
{boolean} Value of property state
getType(): sap.m.SwitchType
Gets current value of property type.

Type of a Switch. Possibles values "Default", "AcceptReject".

Default value is Default.

Returns:
{sap.m.SwitchType} Value of property type
removeAllAriaLabelledBy(): sap.ui.core.Control[]
Removes all the controls in the association named ariaLabelledBy.
Since:
1.27.0
Returns:
{sap.ui.core.Control[]} An array of the removed elements (might be empty)
removeAriaLabelledBy(vAriaLabelledBy): sap.ui.core.Control
Removes an ariaLabelledBy from the association named ariaLabelledBy.
Parameters:
{int|string|sap.ui.core.Control}vAriaLabelledBy The ariaLabelledByto be removed or its index or ID
Since:
1.27.0
Returns:
{sap.ui.core.Control} the removed ariaLabelledBy or null
setCustomTextOff(sCustomTextOff): sap.m.Switch
Sets a new value for property customTextOff.

Custom text for the "OFF" state.

"OFF" translated to the current language is the default value. Beware that the given text will be cut off if available space is exceeded.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is .

Parameters:
{string}sCustomTextOff New value for property customTextOff
Returns:
{sap.m.Switch} Reference to this in order to allow method chaining
setCustomTextOn(sCustomTextOn): sap.m.Switch
Sets a new value for property customTextOn.

Custom text for the "ON" state.

"ON" translated to the current language is the default value. Beware that the given text will be cut off if available space is exceeded.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is .

Parameters:
{string}sCustomTextOn New value for property customTextOn
Returns:
{sap.m.Switch} Reference to this in order to allow method chaining
setEnabled(bEnabled): sap.m.Switch
Sets a new value for property enabled.

Whether the switch is enabled.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is true.

Parameters:
{boolean}bEnabled New value for property enabled
Returns:
{sap.m.Switch} Reference to this in order to allow method chaining
setName(sName): sap.m.Switch
Sets a new value for property name.

The name to be used in the HTML code for the switch (e.g. for HTML forms that send data to the server via submit).

When called with a value of null or undefined, the default value of the property will be restored.

Default value is .

Parameters:
{string}sName New value for property name
Returns:
{sap.m.Switch} Reference to this in order to allow method chaining
setState(bState): sap.m.Switch
Change the switch state between on and off.
Parameters:
{boolean}bState
Returns:
{sap.m.Switch}this to allow method chaining.
setType(sType): sap.m.Switch
Sets a new value for property type.

Type of a Switch. Possibles values "Default", "AcceptReject".

When called with a value of null or undefined, the default value of the property will be restored.

Default value is Default.

Parameters:
{sap.m.SwitchType}sType New value for property type
Returns:
{sap.m.Switch} Reference to this in order to allow method chaining