Class sap.m.ButtonModule: sap/m/Button

extends Control

Enables users to trigger actions. For the button UI, you can define some text or an icon, or both.

Constructor Summary
new sap.m.Button(sId?, mSettings?)Constructor for a new Button.
Event Summary
press(oControlEvent)Event is fired when the user clicks on the control.
tap(oControlEvent)Event is fired when the user taps the control.
Events borrowed from class sap.ui.core.Control
Method Summary
sap.m.Button.extend(sClassName, oClassInfo?, FNMetaImpl?)Creates a new subclass of class sap.m.Button with name sClassName and enriches it with the information contained in oClassInfo.
sap.m.Button.getMetadata()Returns a metadata object for class sap.m.Button.
addAriaDescribedBy(vAriaDescribedBy)Adds some ariaDescribedBy into the association ariaDescribedBy.
addAriaLabelledBy(vAriaLabelledBy)Adds some ariaLabelledBy into the association ariaLabelledBy.
attachPress(oData?, fnFunction, oListener?)Attaches event handler fnFunction to the press event of this sap.m.Button.
detachPress(fnFunction, oListener)Detaches event handler fnFunction from the press event of this sap.m.Button.
firePress(mArguments?)Fires event press to attached listeners.
getActiveIcon()Gets current value of property activeIcon.
getAriaDescribedBy()Returns array of IDs of the elements which are the current targets of the association ariaDescribedBy.
getAriaLabelledBy()Returns array of IDs of the elements which are the current targets of the association ariaLabelledBy.
getEnabled()Gets current value of property enabled.
getIcon()Gets current value of property icon.
getIconDensityAware()Gets current value of property iconDensityAware.
getIconFirst()Gets current value of property iconFirst.
getPopupAnchorDomRef()Defines to which DOM reference the Popup should be docked
getText()Gets current value of property text.
getTextDirection()Gets current value of property textDirection.
getType()Gets current value of property type.
getWidth()Gets current value of property width.
removeAllAriaDescribedBy()Removes all the controls in the association named ariaDescribedBy.
removeAllAriaLabelledBy()Removes all the controls in the association named ariaLabelledBy.
removeAriaDescribedBy(vAriaDescribedBy)Removes an ariaDescribedBy from the association named ariaDescribedBy.
removeAriaLabelledBy(vAriaLabelledBy)Removes an ariaLabelledBy from the association named ariaLabelledBy.
setActiveIcon(sActiveIcon)Sets a new value for property activeIcon.
setEnabled(bEnabled)Sets a new value for property enabled.
setIcon(sIcon)Property setter for the icon
setIconDensityAware(bIconDensityAware)Sets a new value for property iconDensityAware.
setIconFirst(bIconFirst)Sets a new value for property iconFirst.
setText(sText)Property setter for the text
setTextDirection(sTextDirection)Sets a new value for property textDirection.
setType(sType)Sets a new value for property type.
setWidth(sWidth)Sets a new value for property width.
attachTap(oData?, fnFunction, oListener?)Attaches event handler fnFunction to the tap event of this sap.m.Button.
detachTap(fnFunction, oListener)Detaches event handler fnFunction from the tap event of this sap.m.Button.
fireTap(mArguments?)Fires event tap to attached listeners.
Constructor Detail
new sap.m.Button(sId?, mSettings?)
Constructor for a new Button.

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
    • tap : fnListenerFunction or [fnListenerFunction, oListenerObject] or [oData, fnListenerFunction, oListenerObject]
    • press : 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
press(oControlEvent)
Event is fired when the user clicks on the control.
Parameters:
{sap.ui.base.Event}oControlEvent
{sap.ui.base.EventProvider}oControlEvent.getSource
{object}oControlEvent.getParameters
tap(oControlEvent)
Event is fired when the user taps the control.
Parameters:
{sap.ui.base.Event}oControlEvent
{sap.ui.base.EventProvider}oControlEvent.getSource
{object}oControlEvent.getParameters
Deprecated:
Since version 1.20.0. This event is deprecated, use the press event instead.
Method Detail
sap.m.Button.extend(sClassName, oClassInfo?, FNMetaImpl?): function
Creates a new subclass of class sap.m.Button 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.Button.getMetadata(): sap.ui.base.Metadata
Returns a metadata object for class sap.m.Button.
Returns:
{sap.ui.base.Metadata} Metadata object describing this class
addAriaDescribedBy(vAriaDescribedBy): sap.m.Button
Adds some ariaDescribedBy into the association ariaDescribedBy.
Parameters:
{string|sap.ui.core.Control}vAriaDescribedBy the ariaDescribedBy to add; if empty, nothing is inserted
Returns:
{sap.m.Button} Reference to this in order to allow method chaining
addAriaLabelledBy(vAriaLabelledBy): sap.m.Button
Adds some ariaLabelledBy into the association ariaLabelledBy.
Parameters:
{string|sap.ui.core.Control}vAriaLabelledBy the ariaLabelledBy to add; if empty, nothing is inserted
Returns:
{sap.m.Button} Reference to this in order to allow method chaining
attachPress(oData?, fnFunction, oListener?): sap.m.Button
Attaches event handler fnFunction to the press event of this sap.m.Button.

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.Button itself.

Event is fired when the user clicks on the control.

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.Button itself
Returns:
{sap.m.Button} Reference to this in order to allow method chaining
detachPress(fnFunction, oListener): sap.m.Button
Detaches event handler fnFunction from the press event of this sap.m.Button.

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.Button} Reference to this in order to allow method chaining
firePress(mArguments?): sap.m.Button
Fires event press to attached listeners.
Parameters:
{Map}mArguments? The arguments to pass along with the event
Returns:
{sap.m.Button} Reference to this in order to allow method chaining
getAccessibilityInfo()
See:
{sap.ui.core.Control#getAccessibilityInfo}
getActiveIcon(): sap.ui.core.URI
Gets current value of property activeIcon.

The source property of an alternative icon for the active (depressed) state of the button. Both active and default icon properties should be defined and have the same type: image or icon font. If the icon property is not set or has a different type, the active icon is not displayed.

Returns:
{sap.ui.core.URI} Value of property activeIcon
getAriaDescribedBy(): sap.ui.core.Control[]
Returns array of IDs of the elements which are the current targets of the association ariaDescribedBy.
Returns:
{sap.ui.core.Control[]}
getAriaLabelledBy(): sap.ui.core.Control[]
Returns array of IDs of the elements which are the current targets of the association ariaLabelledBy.
Returns:
{sap.ui.core.Control[]}
getEnabled(): boolean
Gets current value of property enabled.

Boolean property to enable the control (default is true). Buttons that are disabled have other colors than enabled ones, depending on custom settings

Default value is true.

Returns:
{boolean} Value of property enabled
getIcon(): sap.ui.core.URI
Gets current value of property icon.

Icon to be displayed as graphical element within the button. This can be an image or an icon from the icon font.

Returns:
{sap.ui.core.URI} Value of property icon
getIconDensityAware(): boolean
Gets current value of property iconDensityAware.

By default, this is set to true but then one or more requests are sent trying to get the density perfect version of image if this version of image doesn't exist on the server.

If only one version of image is provided, set this value to false to avoid the attempt of fetching density perfect image.

Default value is true.

Returns:
{boolean} Value of property iconDensityAware
getIconFirst(): boolean
Gets current value of property iconFirst.

If set to true (default), the display sequence is 1. icon 2. control text

Default value is true.

Returns:
{boolean} Value of property iconFirst
getPopupAnchorDomRef(): DomNode
Defines to which DOM reference the Popup should be docked
Returns:
{DomNode} the DOM reference that Popup should dock to
getText(): string
Gets current value of property text.

Button text

Returns:
{string} Value of property text
getTextDirection(): sap.ui.core.TextDirection
Gets current value of property textDirection.

This property specifies the element's text directionality with enumerated options. By default, the control inherits text direction from the DOM.

Default value is Inherit.

Since:
1.28.0
Returns:
{sap.ui.core.TextDirection} Value of property textDirection
getType(): sap.m.ButtonType
Gets current value of property type.

Type of a button (e.g. Default, Accept, Reject, Back, etc.)

Default value is Default.

Returns:
{sap.m.ButtonType} Value of property type
getWidth(): sap.ui.core.CSSSize
Gets current value of property width.

Defines the width of the button.

Returns:
{sap.ui.core.CSSSize} Value of property width
removeAllAriaDescribedBy(): sap.ui.core.Control[]
Removes all the controls in the association named ariaDescribedBy.
Returns:
{sap.ui.core.Control[]} An array of the removed elements (might be empty)
removeAllAriaLabelledBy(): sap.ui.core.Control[]
Removes all the controls in the association named ariaLabelledBy.
Returns:
{sap.ui.core.Control[]} An array of the removed elements (might be empty)
removeAriaDescribedBy(vAriaDescribedBy): sap.ui.core.Control
Removes an ariaDescribedBy from the association named ariaDescribedBy.
Parameters:
{int|string|sap.ui.core.Control}vAriaDescribedBy The ariaDescribedByto be removed or its index or ID
Returns:
{sap.ui.core.Control} the removed ariaDescribedBy or null
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
Returns:
{sap.ui.core.Control} the removed ariaLabelledBy or null
setActiveIcon(sActiveIcon): sap.m.Button
Sets a new value for property activeIcon.

The source property of an alternative icon for the active (depressed) state of the button. Both active and default icon properties should be defined and have the same type: image or icon font. If the icon property is not set or has a different type, the active icon is not displayed.

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

Parameters:
{sap.ui.core.URI}sActiveIcon New value for property activeIcon
Returns:
{sap.m.Button} Reference to this in order to allow method chaining
setEnabled(bEnabled): sap.m.Button
Sets a new value for property enabled.

Boolean property to enable the control (default is true). Buttons that are disabled have other colors than enabled ones, depending on custom settings

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.Button} Reference to this in order to allow method chaining
setIcon(sIcon): sap.m.Button
Property setter for the icon
Parameters:
{sap.ui.core.URI}sIcon new value of the Icon property
Returns:
{sap.m.Button} this to allow method chaining
setIconDensityAware(bIconDensityAware): sap.m.Button
Sets a new value for property iconDensityAware.

By default, this is set to true but then one or more requests are sent trying to get the density perfect version of image if this version of image doesn't exist on the server.

If only one version of image is provided, set this value to false to avoid the attempt of fetching density perfect image.

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

Default value is true.

Parameters:
{boolean}bIconDensityAware New value for property iconDensityAware
Returns:
{sap.m.Button} Reference to this in order to allow method chaining
setIconFirst(bIconFirst): sap.m.Button
Sets a new value for property iconFirst.

If set to true (default), the display sequence is 1. icon 2. control text

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

Default value is true.

Parameters:
{boolean}bIconFirst New value for property iconFirst
Returns:
{sap.m.Button} Reference to this in order to allow method chaining
setText(sText): sap.m.Button
Property setter for the text
Parameters:
{string}sText new value of the Text attribute
Returns:
{sap.m.Button} this to allow method chaining
setTextDirection(sTextDirection): sap.m.Button
Sets a new value for property textDirection.

This property specifies the element's text directionality with enumerated options. By default, the control inherits text direction from the DOM.

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

Default value is Inherit.

Parameters:
{sap.ui.core.TextDirection}sTextDirection New value for property textDirection
Since:
1.28.0
Returns:
{sap.m.Button} Reference to this in order to allow method chaining
setType(sType): sap.m.Button
Sets a new value for property type.

Type of a button (e.g. Default, Accept, Reject, Back, etc.)

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.ButtonType}sType New value for property type
Returns:
{sap.m.Button} Reference to this in order to allow method chaining
setWidth(sWidth): sap.m.Button
Sets a new value for property width.

Defines the width of the button.

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

Parameters:
{sap.ui.core.CSSSize}sWidth New value for property width
Returns:
{sap.m.Button} Reference to this in order to allow method chaining
attachTap(oData?, fnFunction, oListener?): sap.m.Button
Attaches event handler fnFunction to the tap event of this sap.m.Button.

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.Button itself.

Event is fired when the user taps the control.

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.Button itself
Deprecated:
Since version 1.20.0. This event is deprecated, use the press event instead.
Returns:
{sap.m.Button} Reference to this in order to allow method chaining
detachTap(fnFunction, oListener): sap.m.Button
Detaches event handler fnFunction from the tap event of this sap.m.Button.

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
Deprecated:
Since version 1.20.0. This event is deprecated, use the press event instead.
Returns:
{sap.m.Button} Reference to this in order to allow method chaining
fireTap(mArguments?): sap.m.Button
Fires event tap to attached listeners.
Parameters:
{Map}mArguments? The arguments to pass along with the event
Deprecated:
Since version 1.20.0. This event is deprecated, use the press event instead.
Returns:
{sap.m.Button} Reference to this in order to allow method chaining