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(mParameters?)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

  • Associations

  • 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:
stringsId?id for the new control, generated automatically if no id is given
objectmSettings?initial settings for the new control
Event Detail
change(oControlEvent)
Triggered when a switch changes the state.
Parameters:
sap.ui.base.EventoControlEvent
sap.ui.base.EventProvideroControlEvent.getSource
objectoControlEvent.getParameters
booleanoControlEvent.getParameters.stateThe 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:
stringsClassNameName of the class being created
objectoClassInfo?Object literal with information about the class
functionFNMetaImpl?Constructor function for the metadata object; if not given, it defaults to sap.ui.core.ElementMetadata
Returns:
functionCreated class / constructor function
sap.m.Switch.getMetadata(): sap.ui.base.Metadata
Returns a metadata object for class sap.m.Switch.
Returns:
sap.ui.base.MetadataMetadata object describing this class
addAriaLabelledBy(vAriaLabelledBy): sap.m.Switch
Adds some ariaLabelledBy into the association ariaLabelledBy.
Parameters:
sap.ui.core.ID|sap.ui.core.ControlvAriaLabelledBythe ariaLabelledBy to add; if empty, nothing is inserted
Returns:
sap.m.SwitchReference to this in order to allow method chaining
Since:
1.27.0
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:
objectoData?An application-specific payload object that will be passed to the event handler along with the event object when firing the event
functionfnFunctionThe function to be called when the event occurs
objectoListener?Context object to call the event handler with. Defaults to this sap.m.Switch itself
Returns:
sap.m.SwitchReference 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:
functionfnFunctionThe function to be called, when the event occurs
objectoListenerContext object on which the given function had to be called
Returns:
sap.m.SwitchReference to this in order to allow method chaining
fireChange(mParameters?): sap.m.Switch
Fires event change to attached listeners.
Parameters:
objectmParameters?Parameters to pass along with the event
booleanmParameters.state?The new state of the switch.
Returns:
sap.m.SwitchReference to this in order to allow method chaining
getAriaLabelledBy(): sap.ui.core.ID[]
Returns array of IDs of the elements which are the current targets of the association ariaLabelledBy.
Returns:
sap.ui.core.ID[]
Since:
1.27.0
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:
stringValue 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:
stringValue of property customTextOn
getEnabled(): boolean

Gets current value of property enabled.

Whether the switch is enabled.

Default value is true.

Returns:
booleanValue 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:
stringValue 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:
booleanValue 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.SwitchTypeValue of property type
removeAllAriaLabelledBy(): sap.ui.core.ID[]
Removes all the controls in the association named ariaLabelledBy.
Returns:
sap.ui.core.ID[]An array of the removed elements (might be empty)
Since:
1.27.0
removeAriaLabelledBy(vAriaLabelledBy): sap.ui.core.ID
Removes an ariaLabelledBy from the association named ariaLabelledBy.
Parameters:
int|sap.ui.core.ID|sap.ui.core.ControlvAriaLabelledByThe ariaLabelledBy to be removed or its index or ID
Returns:
sap.ui.core.IDThe removed ariaLabelledBy or null
Since:
1.27.0
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:
stringsCustomTextOffNew value for property customTextOff
Returns:
sap.m.SwitchReference 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:
stringsCustomTextOnNew value for property customTextOn
Returns:
sap.m.SwitchReference 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:
booleanbEnabledNew value for property enabled
Returns:
sap.m.SwitchReference 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:
stringsNameNew value for property name
Returns:
sap.m.SwitchReference to this in order to allow method chaining
setState(bState): sap.m.Switch
Change the switch state between on and off.
Parameters:
booleanbState
Returns:
sap.m.Switchthis 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.SwitchTypesTypeNew value for property type
Returns:
sap.m.SwitchReference to this in order to allow method chaining