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 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 |
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 |
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). |
Method | Description |
---|---|
addAriaLabelledBy |
Adds some ariaLabelledBy into the association ariaLabelledBy. |
attachChange |
Attaches event handler When called, the context of the event handler (its Triggered when a switch changes the state. |
detachChange |
Detaches event handler 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
|
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 |
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 |
getEnabled |
Gets current value of property enabled. Whether the switch is enabled. Default value is |
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 |
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 |
getType |
Gets current value of property type. Type of a Switch. Possibles values "Default", "AcceptReject". Default value is |
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 Default value is |
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 Default value is |
setEnabled |
Sets a new value for property enabled. Whether the switch is enabled. When called with a value of Default value is |
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 Default value is |
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 Default value is |
setType |
Sets a new value for property type. Type of a Switch. Possibles values "Default", "AcceptReject". When called with a value of Default value is |
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 |
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 |
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 |
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 |
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. |
Returns array of IDs of the elements which are the current targets of the association ariaLabelledBy.
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
.
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
.
Gets current value of property enabled.
Whether the switch is enabled.
Default value is true
.
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
.
Gets current value of property state.
A boolean value indicating whether the switch is on or off.
Default value is false
.
Gets current value of property type.
Type of a Switch. Possibles values "Default", "AcceptReject".
Default value is Default
.
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 |
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 |
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 |
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 |
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 |
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 |
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 |