RadioButton

RadioButton is a component used to select of multiple option by clicking on it. Multiple RadioButton components must be grouped for selection to work. To group them pick one main RadioButton and group other RadioButton components with it. For example if you have three RadioButton components, you must group second component with first one, then third component with any component that is already grouped (first or second). Then to detect selection changes add onChange(e => {console.log(e.value);}) to only one of the grouped RadioButton components, and e.value will be the value of currently selected RadioButton.

Constructor

new RadioButton(textopt)

RadioButton constructor. Creates an instance of RadioButton UI component.

Parameters:
NameTypeAttributesDescription
textstring<optional>

Text of the radio button component.

Example
// Example how to group RadioButton components and detect when selected value of a group changes.

var mainForm = new Window("Demo").size(500, 300).show();

// create first RadioButton and sets group value change handler function
mainForm.radio1 = new RadioButton("Option 1").addTo(mainForm).position(10, 10).onChange(e => {console.log(e.value);});

// create second RadioButton and group it with first one
mainForm.radio2 = new RadioButton("Option 2").addTo(mainForm).position(10, 30).groupWith(mainForm.radio1);

// create third RadioButton and group it with first one
mainForm.radio3 = new RadioButton("Option 3").addTo(mainForm).position(10, 50).groupWith(mainForm.radio1);

// now when user clicks on any of these radio buttons a new selected value will be logged in console.

Classes

RadioButton

Members

(readonly) group :Array.<RadioButton>

Retrieves an array of RadioButton components grouped with this component (including this component). Returns an array of minimum one (current) item.

Type:

Methods

clearSelection() → {RadioButton}

Deselect all RadioButton elements grouped with this element.

Returns:

Returns this component.

Type: 
RadioButton

groupWith(componentopt) → {RadioButton}

Adds this RadioButton to the group of another RadioButton, or removes it from its current group.

  • Pass another RadioButtonMenuItem to join its group.
  • Pass null to leave the current group (if any).
Parameters:
NameTypeAttributesDescription
componentRadioButton | null<optional>

A RadioButton to join, or null to leave the current group.

Returns:

This RadioButton, for chaining.

Type: 
RadioButton

selected(selectedopt) → {RadioButtonMenuItem|boolean}

Sets or gets boolean indicating whether this component is selected.

Parameters:
NameTypeAttributesDescription
selectedboolean<optional>

true to select, false to deselect.

Returns:

Returns this CheckBoxMenuItem instance if argument is provided, otherwise returns boolean value.

Type: 
RadioButtonMenuItem | boolean

selectedValue() → {RadioButtonMenuItem|*}

Selects a radio button in the group of this component and has the specified value, or returns the value of selected radio button grouped with this component.

Returns:
Type: 
RadioButtonMenuItem | *

value(valueopt) → {RadioButton|*}

Sets or gets a value of this component.

Parameters:
NameTypeAttributesDescription
value*<optional>

Value to be held by this component

Returns:

If setting a value, then an instance of this component is returned, otherwise current value is returned.

Type: 
RadioButton | *