class sap.m.Switch

Control sample: sap.m.Switch
Visiblity: public
UX Guidelines: Switch
Implements: sap.ui.core.IFormContentsap.m.IOverflowToolbarContent
Available since: N/A
Module: sap/m/Switch
Application Component: CA-UI5-CTR

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

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#constructor for a general description of the syntax of the settings object.

new sap.m.Switch(sId?, mSettings?)
Param Type Default Value Description
sId? string

id for the new control, generated automatically if no id is given

mSettings? object

initial settings for the new control


Properties

Name Type Default Value Description
customTextOff string empty string

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.

Visibility: public
customTextOn string empty string

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.

Visibility: public
enabled boolean true

Whether the switch is enabled.

Visibility: public
name string empty string

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).

Visibility: public
state boolean false

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

Visibility: public
type sap.m.SwitchType Default

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

Visibility: public

Associations

Name Cardinality Type Description
ariaLabelledBy 0..n sap.ui.core.Control

Association to controls / ids which label this control (see WAI-ARIA attribute aria-labelledby).

Since: 1.27.0.


Events Overview

Event Description
change

Triggered when a switch changes the state.

change

Triggered when a switch changes the state.

Param Type Description
oControlEvent sap.ui.base.Event
getSource sap.ui.base.EventProvider
getParameters object
state boolean

The new state of the switch.


Methods Overview

Method Description
addAriaLabelledBy

Adds some ariaLabelledBy into the association ariaLabelledBy.

attachChange

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.

detachChange

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.

sap.m.Switch.extend

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.

fireChange

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.

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 empty string.

getCustomTextOn

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 empty string.

getEnabled

Gets current value of property enabled.

Whether the switch is enabled.

Default value is true.

sap.m.Switch.getMetadata

Returns a metadata object for class sap.m.Switch.

getName

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 empty string.

getOverflowToolbarConfig

Required by the sap.m.IOverflowToolbarContent interface.

getState

Gets current value of property state.

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

Default value is false.

getType

Gets current value of property type.

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

Default value is Default.

removeAllAriaLabelledBy

Removes all the controls in the association named ariaLabelledBy.

removeAriaLabelledBy

Removes an ariaLabelledBy from the association named ariaLabelledBy.

setCustomTextOff

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 empty string.

setCustomTextOn

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 empty string.

setEnabled

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.

setName

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 empty string.

setState

Sets a new value for property state.

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

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

Default value is false.

setType

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.

addAriaLabelledBy

Adds some ariaLabelledBy into the association ariaLabelledBy.

Param Type DefaultValue Description
vAriaLabelledBy sap.ui.core.ID sap.ui.core.Control

The ariaLabelledBy to add; if empty, nothing is inserted

attachChange

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.

Param Type DefaultValue Description
oData object

An application-specific payload object that will be passed to the event handler along with the event object when firing the event

fnFunction function(sap.ui.base.Event) : void

The function to be called when the event occurs

oListener object

Context object to call the event handler with. Defaults to this sap.m.Switch itself

detachChange

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.

Param Type DefaultValue Description
fnFunction function(sap.ui.base.Event) : void

The function to be called, when the event occurs

oListener object

Context object on which the given function had to be called

sap.m.Switch.extend

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.

Param Type DefaultValue Description
sClassName string

Name of the class being created

oClassInfo object

Object literal with information about the class

FNMetaImpl function

Constructor function for the metadata object; if not given, it defaults to the metadata implementation used by this class

fireChange

Fires event change to attached listeners.

Param Type DefaultValue Description
mParameters object

Parameters to pass along with the event

state boolean

The new state of the switch.

getAriaLabelledBy

Returns array of IDs of the elements which are the current targets of the association ariaLabelledBy.

getCustomTextOff

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 empty string.

getCustomTextOn

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 empty string.

getEnabled

Gets current value of property enabled.

Whether the switch is enabled.

Default value is true.

sap.m.Switch.getMetadata

Returns a metadata object for class sap.m.Switch.

getName

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 empty string.

getOverflowToolbarConfig

Required by the sap.m.IOverflowToolbarContent interface.

getState

Gets current value of property state.

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

Default value is false.

getType

Gets current value of property type.

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

Default value is Default.

removeAllAriaLabelledBy

Removes all the controls in the association named ariaLabelledBy.

removeAriaLabelledBy

Removes an ariaLabelledBy from the association named ariaLabelledBy.

Param Type DefaultValue Description
vAriaLabelledBy int sap.ui.core.ID sap.ui.core.Control

The ariaLabelledBy to be removed or its index or ID

setCustomTextOff

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 empty string.

Param Type DefaultValue Description
sCustomTextOff string ""

New value for property customTextOff

setCustomTextOn

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 empty string.

Param Type DefaultValue Description
sCustomTextOn string ""

New value for property customTextOn

setEnabled

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.

Param Type DefaultValue Description
bEnabled boolean true

New value for property enabled

setName

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 empty string.

Param Type DefaultValue Description
sName string ""

New value for property name

setState

Sets a new value for property state.

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

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

Default value is false.

Param Type DefaultValue Description
bState boolean false

New value for property state

setType

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.

Param Type DefaultValue Description
sType sap.m.SwitchType Default

New value for property type