Class sap.m.RadioButtonModule: sap/m/RadioButton

extends Control
implements IFormContent

RadioButton is a control similar to a checkbox, but it allows you to choose only one of the predefined set of options. Multiple radio buttons have to belong to the same group (have the same value for groupName) in order to be mutually exclusive. A wrapper control RadioButtonGroup can be used instead of individual radio buttons.

Structure

  • Radio buttons can have a value state like Error or Warning.
  • Radio buttons can be arranged vertically by setting the column to a number higher than 1.
  • Radio button options need to have a label.

Usage

When to use:

  • You quickly need to choose between at least two alternatives.
  • You need to place other controls between the radio button options.

When not to use:

  • You want to select multiple values for the same option. Use checkboxes instead.
  • When the default value is recommended for most users in most situations. Use a drop-down instead as is saves space by not showing all the alternatives.
  • You want have more than 8 options. Use a drop-down instead.
  • When the options are mutually exclusive e.g. ON/OFF. Use a switch instead.
  • Avoid using horizontally aligned radio buttons as they will be cut off on phones.
Constructor Summary
new sap.m.RadioButton(sId?, mSettings?)Constructor for a new RadioButton.
Event Summary
select(oControlEvent)Event is triggered when the user makes a change on the radio button (selecting or unselecting it).
Events borrowed from class sap.ui.core.Control
Method Summary
sap.m.RadioButton.extend(sClassName, oClassInfo?, FNMetaImpl?)Creates a new subclass of class sap.m.RadioButton with name sClassName and enriches it with the information contained in oClassInfo.
sap.m.RadioButton.getMetadata()Returns a metadata object for class sap.m.RadioButton.
addAriaDescribedBy(vAriaDescribedBy)Adds some ariaDescribedBy into the association ariaDescribedBy.
addAriaLabelledBy(vAriaLabelledBy)Adds some ariaLabelledBy into the association ariaLabelledBy.
attachSelect(oData?, fnFunction, oListener?)Attaches event handler fnFunction to the select event of this sap.m.RadioButton.
detachSelect(fnFunction, oListener)Detaches event handler fnFunction from the select event of this sap.m.RadioButton.
exit()Destroys all related objects to the RadioButton
fireSelect(mParameters?)Fires event select to attached listeners.
getActiveHandling()Gets current value of property activeHandling.
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.
getEditable()Gets current value of property editable.
getEnabled()Gets current value of property enabled.
getGroupName()Gets current value of property groupName.
getSelected()Gets current value of property selected.
getText()Gets current value of property text.
getTextAlign()Gets current value of property textAlign.
getTextDirection()Gets current value of property textDirection.
getUseEntireWidth()Gets current value of property useEntireWidth.
getValueState()Gets current value of property valueState.
getWidth()Gets current value of property width.
onsapselect(oEvent)Pseudo event for pseudo 'select' event.
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.
setActiveHandling(bActiveHandling)Sets a new value for property activeHandling.
setActiveState(bActive)Method to set a RadioButton's state to active or inactive.
setEditable(bEditable)Sets a new value for property editable.
setEnabled(bEnabled)Sets a new value for property enabled.
setGroupName(sGroupName)Sets RadioButton's groupName.
setSelected(bSelected)Sets the state of the RadioButton to selected.
setText(sText)Sets the text for the RadioButton's label.
setTextAlign(sTextAlign)Sets a new value for property textAlign.
setTextDirection(sDirection)Sets the text direction for the RadioButton's label.
setUseEntireWidth(bUseEntireWidth)Sets a new value for property useEntireWidth.
setValueState(sValueState)Sets a new value for property valueState.
setWidth(sWidth)Sets a new value for property width.
Constructor Detail
new sap.m.RadioButton(sId?, mSettings?)

Constructor for a new RadioButton.

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

    • select : 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 Enables users to select a single option from a set of options.
Event Detail
select(oControlEvent)
Event is triggered when the user makes a change on the radio button (selecting or unselecting it).
Parameters:
sap.ui.base.EventoControlEvent
sap.ui.base.EventProvideroControlEvent.getSource
objectoControlEvent.getParameters
booleanoControlEvent.getParameters.selectedChecks whether the RadioButton is active or not.
Method Detail
sap.m.RadioButton.extend(sClassName, oClassInfo?, FNMetaImpl?): function

Creates a new subclass of class sap.m.RadioButton 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.RadioButton.getMetadata(): sap.ui.base.Metadata
Returns a metadata object for class sap.m.RadioButton.
Returns:
sap.ui.base.MetadataMetadata object describing this class
addAriaDescribedBy(vAriaDescribedBy): sap.m.RadioButton
Adds some ariaDescribedBy into the association ariaDescribedBy.
Parameters:
sap.ui.core.ID|sap.ui.core.ControlvAriaDescribedBythe ariaDescribedBy to add; if empty, nothing is inserted
Returns:
sap.m.RadioButtonReference to this in order to allow method chaining
addAriaLabelledBy(vAriaLabelledBy): sap.m.RadioButton
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.RadioButtonReference to this in order to allow method chaining
attachSelect(oData?, fnFunction, oListener?): sap.m.RadioButton

Attaches event handler fnFunction to the select event of this sap.m.RadioButton.

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

Event is triggered when the user makes a change on the radio button (selecting or unselecting it).

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.RadioButton itself
Returns:
sap.m.RadioButtonReference to this in order to allow method chaining
detachSelect(fnFunction, oListener): sap.m.RadioButton

Detaches event handler fnFunction from the select event of this sap.m.RadioButton.

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.RadioButtonReference to this in order to allow method chaining
exit()
Destroys all related objects to the RadioButton
fireSelect(mParameters?): sap.m.RadioButton
Fires event select to attached listeners.
Parameters:
objectmParameters?Parameters to pass along with the event
booleanmParameters.selected?Checks whether the RadioButton is active or not.
Returns:
sap.m.RadioButtonReference to this in order to allow method chaining
getActiveHandling(): boolean

Gets current value of property activeHandling.

This is a flag to switch on activeHandling. When it is switched off, there will not be visual changes on active state. Default value is 'true'

Default value is true.

Returns:
booleanValue of property activeHandling
getAriaDescribedBy(): sap.ui.core.ID[]
Returns array of IDs of the elements which are the current targets of the association ariaDescribedBy.
Returns:
sap.ui.core.ID[]
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[]
getEditable(): boolean

Gets current value of property editable.

Specifies whether the user can select the radio button.

Default value is true.

Returns:
booleanValue of property editable
Since:
1.25
getEnabled(): boolean

Gets current value of property enabled.

Specifies if the radio button is disabled.

Default value is true.

Returns:
booleanValue of property enabled
getGroupName(): string

Gets current value of property groupName.

Name of the radio button group the current radio button belongs to. You can define a new name for the group. If no new name is specified, this radio button belongs to the sapMRbDefaultGroup per default. Default behavior of a radio button in a group is that when one of the radio buttons in a group is selected, all others are unselected.

Default value is sapMRbDefaultGroup.

Returns:
stringValue of property groupName
getSelected(): boolean

Gets current value of property selected.

Specifies the select state of the radio button

Default value is false.

Returns:
booleanValue of property selected
getText(): string

Gets current value of property text.

Specifies the text displayed next to the RadioButton

Returns:
stringValue of property text
getTextAlign(): sap.ui.core.TextAlign

Gets current value of property textAlign.

Specifies the alignment of the radio button. Available alignment settings are "Begin", "Center", "End", "Left", and "Right".

Default value is Begin.

Returns:
sap.ui.core.TextAlignValue of property textAlign
Since:
1.28
getTextDirection(): sap.ui.core.TextDirection

Gets current value of property textDirection.

Options for the text direction are RTL and LTR. Alternatively, the control can inherit the text direction from its parent container.

Default value is Inherit.

Returns:
sap.ui.core.TextDirectionValue of property textDirection
getUseEntireWidth(): boolean

Gets current value of property useEntireWidth.

Indicates if the given width will be applied for the whole RadioButton or only it's label. By Default width is set only for the label.

Default value is false.

Returns:
booleanValue of property useEntireWidth
Since:
1.42
getValueState(): sap.ui.core.ValueState

Gets current value of property valueState.

Enumeration sap.ui.core.ValueState provides state values Error, Success, Warning, None

Default value is None.

Returns:
sap.ui.core.ValueStateValue of property valueState
Since:
1.25
getWidth(): sap.ui.core.CSSSize

Gets current value of property width.

Width of the RadioButton or it's label depending on the useEntireWidth property. By Default width is set only for the label.

Default value is .

Returns:
sap.ui.core.CSSSizeValue of property width
onsapselect(oEvent)
Pseudo event for pseudo 'select' event... space, enter, ... without modifiers (Ctrl, Alt or Shift)
Parameters:
objectoEventprovides information for the event
removeAllAriaDescribedBy(): sap.ui.core.ID[]
Removes all the controls in the association named ariaDescribedBy.
Returns:
sap.ui.core.ID[]An array of the removed elements (might be empty)
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)
removeAriaDescribedBy(vAriaDescribedBy): sap.ui.core.ID
Removes an ariaDescribedBy from the association named ariaDescribedBy.
Parameters:
int|sap.ui.core.ID|sap.ui.core.ControlvAriaDescribedByThe ariaDescribedBy to be removed or its index or ID
Returns:
sap.ui.core.IDThe removed ariaDescribedBy or null
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
setActiveHandling(bActiveHandling): sap.m.RadioButton

Sets a new value for property activeHandling.

This is a flag to switch on activeHandling. When it is switched off, there will not be visual changes on active state. Default value is 'true'

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

Default value is true.

Parameters:
booleanbActiveHandlingNew value for property activeHandling
Returns:
sap.m.RadioButtonReference to this in order to allow method chaining
setActiveState(bActive): void
Method to set a RadioButton's state to active or inactive.
Parameters:
booleanbActiveSets the active state to true or false
setEditable(bEditable): sap.m.RadioButton

Sets a new value for property editable.

Specifies whether the user can select the radio button.

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

Default value is true.

Parameters:
booleanbEditableNew value for property editable
Returns:
sap.m.RadioButtonReference to this in order to allow method chaining
Since:
1.25
setEnabled(bEnabled): sap.m.RadioButton

Sets a new value for property enabled.

Specifies if the radio button is disabled.

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.RadioButtonReference to this in order to allow method chaining
setGroupName(sGroupName): sap.m.RadioButton
Sets RadioButton's groupName. Only one radioButton from the same group can be selected
Parameters:
stringsGroupNameName of the group to which the RadioButton will belong.
Returns:
sap.m.RadioButtonReference to the control instance for chaining
setSelected(bSelected): sap.m.RadioButton
Sets the state of the RadioButton to selected.
Parameters:
booleanbSelecteddefines if the radio button is selected
Returns:
sap.m.RadioButtonReference to the control instance for chaining
setText(sText): sap.m.RadioButton
Sets the text for the RadioButton's label.
Parameters:
stringsTextThe text to be set
Returns:
sap.m.RadioButtonReference to the control instance for chaining
setTextAlign(sTextAlign): sap.m.RadioButton

Sets a new value for property textAlign.

Specifies the alignment of the radio button. Available alignment settings are "Begin", "Center", "End", "Left", and "Right".

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

Default value is Begin.

Parameters:
sap.ui.core.TextAlignsTextAlignNew value for property textAlign
Returns:
sap.m.RadioButtonReference to this in order to allow method chaining
Since:
1.28
setTextDirection(sDirection): sap.m.RadioButton
Sets the text direction for the RadioButton's label.
Parameters:
stringsDirectionText direction to be set to RadioButton's label
Returns:
sap.m.RadioButtonReference to the control instance for chaining
setUseEntireWidth(bUseEntireWidth): sap.m.RadioButton

Sets a new value for property useEntireWidth.

Indicates if the given width will be applied for the whole RadioButton or only it's label. By Default width is set only for the label.

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

Default value is false.

Parameters:
booleanbUseEntireWidthNew value for property useEntireWidth
Returns:
sap.m.RadioButtonReference to this in order to allow method chaining
Since:
1.42
setValueState(sValueState): sap.m.RadioButton

Sets a new value for property valueState.

Enumeration sap.ui.core.ValueState provides state values Error, Success, Warning, None

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

Default value is None.

Parameters:
sap.ui.core.ValueStatesValueStateNew value for property valueState
Returns:
sap.m.RadioButtonReference to this in order to allow method chaining
Since:
1.25
setWidth(sWidth): sap.m.RadioButton

Sets a new value for property width.

Width of the RadioButton or it's label depending on the useEntireWidth property. By Default width is set only for the label.

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

Default value is .

Parameters:
sap.ui.core.CSSSizesWidthNew value for property width
Returns:
sap.m.RadioButtonReference to this in order to allow method chaining