1. Domino UI
  2. Forms
  3. Radio
Top Basic Docs

Basic radio button

Radio group

Represents a group of radio buttons, ensuring that only one radio button in the group can be selected at a time.

This implementation guarantees that radio buttons belonging to the same group have the same name attribute. It provides an API for managing the radio buttons as a group and ensures that selecting one radio deselects others in the same group.

T

The type of the value associated with the radio buttons in the group.

Radio

The Radio class represents a radio button element in a Domino UI form.

Radio buttons are typically used to allow users to make a single selection from a list of options. A radio button can have a label and optional helper text.

Usage Example:

  Radio< String>  radio = Radio.create("option1", "Option 1");
 radio.setHelperText("Select option 1"); radio.addValueChangeHandler(value -> {
 Window.alert("Selected value: " + value); }); 

T

The type of value associated with the radio button.

See also :

Examples

Radio Select only one option from a group.

API Docs: RadioGroup

Constructors

public void RadioGroup(String name)
Constructs a radio group with the given name. This name will be set as the name attribute of each radio button in the group.

name

The name attribute for the radio group.

public void RadioGroup(String name, String label)
Constructs a radio group with the given name and label. This name will be set as the name attribute of each radio button in the group.

name

The name attribute for the radio group.

label

The label for the radio group.

Static methods

public static RadioGroup<T> create(String name)
Factory method to create a new RadioGroup with the specified name.

T

The type of the value associated with the radio buttons in the group.

name

The name attribute for the radio group.



Returns:

A new instance of RadioGroup.

public static RadioGroup<T> create(String name, String label)
Factory method to create a new RadioGroup with the specified name and label.

T

The type of the value associated with the radio buttons in the group.

name

The name attribute for the radio group.

label

The label for the radio group.



Returns:

A new instance of RadioGroup.

Public methods

public RadioGroup<T> withGap(boolean withGap)
Configures the gap style for the radio group. When set to true, the radio group will have gaps between the radio border and the selected indicator circle at the middle.

withGap

A boolean flag indicating whether to add gaps between radio the radio border and the selected indicator circle at the middle.



Returns:

The instance of the RadioGroup .

public RadioGroup<T> appendChild(Radio<? extends T> radio)
Appends a radio button to the group, setting its name to match the group's name, and making sure only one radio button is checked at a time.

radio

The Radio to be appended to the group.



Returns:

The instance of the RadioGroup .

public RadioGroup<T> removeRadio(Radio<? extends T> radio, boolean silent)
Removes a specified radio button from the group. The radio button will be unchecked and removed from the DOM.

radio

The Radio to be removed.

silent

A boolean flag indicating if the uncheck action should trigger events.



Returns:

The instance of the RadioGroup .

public RadioGroup<T> removeAllRadios(boolean silent)
Removes all radio buttons from the group.

silent

A boolean flag indicating if the uncheck action for each radio should trigger events.



Returns:

The instance of the RadioGroup .

public RadioGroup<T> clear(boolean silent)
Clears the selection of the radio group. If a default value is set, the radio button with the matching value will be checked, otherwise, the first radio button in the group will be checked.

silent

A boolean flag indicating if the check action should trigger events.



Returns:

The instance of the RadioGroup .

public RadioGroup<T> triggerChangeListeners(T oldValue, T newValue)
Notifies all registered change listeners about a value change in the group.

oldValue

The old value of the group before the change.

newValue

The new value of the group after the change.



Returns:

The instance of the RadioGroup .

public RadioGroup<T> triggerClearListeners(T oldValue)
Notifies all registered clear listeners about a value clear in the group.

oldValue

The old value of the group before the clear action.



Returns:

The instance of the RadioGroup .

public String getType()
Retrieves the type of the form element.

Returns:

A string representation of the form element type, which is "RadioGroup".

public RadioGroup<T> withValue(T value)
Sets the value of the radio group to the specified value, and checks the corresponding radio button with that value. The change listeners will be triggered if they are not paused.

value

The value to set for the radio group.



Returns:

The instance of the RadioGroup .

public RadioGroup<T> withValue(T value, boolean silent)
Sets the value of the radio group to the specified value, and checks the corresponding radio button with that value.

value

The value to set for the radio group.

silent

A boolean flag indicating if the check action should trigger events.



Returns:

The instance of the RadioGroup .

public RadioGroup<T> vertical()
Sets the layout of the radio buttons in the group to be vertical.

Returns:

The instance of the RadioGroup .

public RadioGroup<T> horizontal()
Sets the layout of the radio buttons in the group to be horizontal.

Returns:

The instance of the RadioGroup .

public RadioGroup<T> vertical(boolean vertical)
Toggles the layout of the radio buttons in the group based on the vertical parameter.

vertical

A boolean indicating if the radio buttons should be arranged vertically.



Returns:

The instance of the RadioGroup .

public List<Radio<? extends T>> getRadios()
Retrieves the list of radio buttons that belong to the group.

Returns:

A list of radio buttons.

public RadioGroup<T> withRadios(ChildHandler<RadioGroup<T>, List<Radio<? extends T>>> handler)
Allows manipulation of the list of radio buttons that belong to the group.

handler

A handler to apply changes to the list of radio buttons.



Returns:

The instance of the RadioGroup .

public boolean isSelected()
Checks if any radio button in the group is selected.

Returns:

A boolean indicating if a radio button is selected.

public T getValue()
Retrieves the value of the selected radio button from the group.

Returns:

The value of the selected radio button, or null if no button is selected.

public boolean isEmpty()
Checks if the radio group has no selected value.

Returns:

true if the group has no selected radio button, otherwise false .

public boolean isEmptyIgnoreSpaces()
Checks if the radio group has no selected value, ignoring any spaces. This is functionally identical to isEmpty for radio groups.

Returns:

true if the group has no selected radio button, otherwise false .

public RadioGroup<T> clear()
Clears any selected value in the radio group.

Returns:

The instance of the RadioGroup .

public String getName()
Retrieves the name attribute of the radio group.

Returns:

The name attribute of the radio group.

public RadioGroup<T> setName(String name)
Sets the name attribute for the radio group and all its radio buttons.

name

The new name attribute to set.



Returns:

The instance of the RadioGroup .

public RadioGroup<T> enable()
Enables all radio buttons within the radio group.

Returns:

The instance of the RadioGroup .

public RadioGroup<T> disable()
Disables all radio buttons within the radio group.

Returns:

The instance of the RadioGroup .

public boolean isEnabled()
Checks if the radio group and all its radio buttons are enabled.

Returns:

true if all radio buttons are enabled, otherwise false .

public void setValue(Radio<T> value)
Sets the value for the radio group. This will check the radio button that has the specified value.

value

The value to be set.

public void setValue(T value, boolean silent)
Sets the value for the radio group, with an option to silence any change listeners. This will check the radio button that matches the specified value.

value

The value to be set.

silent

If true, change listeners will not be notified.

public Radio<? extends T> getSelectedRadio()
Gets the radio button that is currently selected in the group.

Returns:

The selected radio button, or null if none is selected.

public AutoValidator createAutoValidator(ApplyFunction autoValidate)
Creates an auto validator for the radio group. The auto validator will automatically validate the radio group based on the provided function.

autoValidate

A function to apply the auto-validation logic.



Returns:

An instance of AutoValidator for the radio group.

API Docs: Radio

Constructors

public void Radio(T value, String label)
Creates a new Radio instance with the specified value and label.

value

The value associated with the radio button.

label

The label text for the radio button.

public void Radio(T value)
Creates a new Radio instance with the specified value and a label generated from the value.

value

The value associated with the radio button.

Static methods

public static Radio<E> create(E value, String label)
Creates a new Radio instance with the specified value and label.

E

The type of value associated with the radio button.

value

The value associated with the radio button.

label

The label text for the radio button.



Returns:

A new Radio instance.

public static Radio<E> create(E value)
Creates a new Radio instance with the specified value and a label generated from the value.

E

The type of value associated with the radio button.

value

The value associated with the radio button.



Returns:

A new Radio instance.

Public methods

public String getType()
Gets the type of the radio button input, which is always "radio".

Returns:

The type of the radio button input, which is "radio".

public Radio<T> check()
Checks the radio button, triggering change listeners if not in a paused state.

Returns:

This `Radio` instance.

public Radio<T> uncheck()
Unchecks the radio button, triggering change listeners if not in a paused state.

Returns:

This `Radio` instance.

public Radio<T> check(boolean silent)
Checks the radio button, optionally suppressing change listener events if `silent` is true.

silent

If true, change listener events will not be triggered.



Returns:

This `Radio` instance.

public Radio<T> uncheck(boolean silent)
Unchecks the radio button, optionally suppressing change listener events if `silent` is true.

silent

If true, change listener events will not be triggered.



Returns:

This `Radio` instance.

public Radio<T> toggleChecked(boolean silent)
Toggles the checked state of the radio button, optionally suppressing change listener events if `silent` is true.

silent

If true, change listener events will not be triggered.



Returns:

This `Radio` instance.

public Radio<T> toggleChecked(boolean checkedState, boolean silent)
Toggles the checked state of the radio button to the specified `checkedState`, optionally suppressing change listener events if `silent` is true.

checkedState

The desired checked state.

silent

If true, change listener events will not be triggered.



Returns:

This `Radio` instance.

public Radio<T> toggleChecked()
Toggles the checked state of the radio button, optionally suppressing change listener events if not in a paused state.

Returns:

This `Radio` instance.

public boolean isChecked()
Checks if the radio button is currently checked.

Returns:

True if the radio button is checked, false otherwise.

public HTMLDivElement element()
Gets the DOM element representing this radio button.

Returns:

The DOM element of this radio button.

public Radio<T> withValue(T value)
Sets the value of the radio button and optionally triggers change listeners.

value

The value to set.



Returns:

This `Radio` instance.

public Radio<T> withValue(T value, boolean silent)
Sets the value of the radio button and optionally triggers change listeners.

value

The value to set.

silent

If `true`, change listeners won't be triggered.



Returns:

This `Radio` instance.

public void setValue(T value)
Sets the value of the radio button.

value

The value to set.

public T getValue()
Gets the current value of the radio button.

Returns:

The current value of the radio button.

public Radio<T> setLabel(String label)
Sets the label of the radio button.

label

The label text to set.



Returns:

This `Radio` instance.

public Radio<T> setLabel(SafeHtml safeHtml)
Sets the label of the radio button with HTML content provided as SafeHtml.

safeHtml

The SafeHtml content to set as the label.



Returns:

This `Radio` instance.

public Radio<T> setLabel(Node node)
Sets the label of the radio button with a custom DOM Node element.

node

The DOM Node element to set as the label.



Returns:

This `Radio` instance.

public Radio<T> setLabel(IsElement<?> element)
Sets the label of the radio button with an IsElement instance.

element

The IsElement instance whose element will be set as the label.



Returns:

This `Radio` instance.

public String getLabel()
Gets the text content of the radio button's label.

Returns:

The text content of the radio button's label.

public Radio<T> enable()
Enables the radio button for user interaction.

Returns:

This `Radio` instance.

public Radio<T> disable()
Disables the radio button, preventing user interaction.

Returns:

This `Radio` instance.

public String getHelperText()
Retrieves the helper text associated with this radio button.

Returns:

The helper text.

public Radio<T> setHelperText(String text)
Sets the helper text for this radio button.

text

The helper text to set.



Returns:

This `Radio` instance.

public boolean isEnabled()
Checks if the radio button is enabled for user interaction.

Returns:

`true` if the radio button is enabled, `false` otherwise.

public DominoElement<HTMLInputElement> getInputElement()
Retrieves the input element associated with this radio button.

Returns:

The input element.

public String getStringValue()
Retrieves the string representation of the current value of this radio button.

Returns:

The string representation of the value.

public Radio<T> focus()
Sets focus on the radio button element if it's not disabled.

Returns:

This `Radio` instance.

public Radio<T> unfocus()
Removes focus from the radio button element.

Returns:

This `Radio` instance.

public boolean isFocused()
Checks if the radio button element is currently focused.

Returns:

`true` if the radio button is focused, `false` otherwise.

public Radio<T> labelForId(String id)
Associates the given `id` with the label element for accessibility purposes.

id

The `id` to associate with the label.



Returns:

This `Radio` instance.

public Radio<T> pauseChangeListeners()
Pauses change listeners for this radio button.

Returns:

This `Radio` instance.

public Radio<T> resumeChangeListeners()
Resumes change listeners for this radio button.

Returns:

This `Radio` instance.

public Radio<T> togglePauseChangeListeners(boolean toggle)
Toggles the pause state of change listeners for this radio button.

toggle

`true` to pause change listeners, `false` to resume.



Returns:

This `Radio` instance.

public Set<ChangeListener<? super Boolean>> getChangeListeners()
Retrieves the set of change listeners associated with this radio button.

Returns:

The set of change listeners.

public boolean isChangeListenersPaused()
Checks if change listeners for this radio button are currently paused.

Returns:

`true` if change listeners are paused, `false` otherwise.

public Radio<T> triggerChangeListeners(Boolean oldValue, Boolean newValue)
Triggers change listeners for this radio button with the given old and new values.

oldValue

The old value.

newValue

The new value.



Returns:

This `Radio` instance.

public DivElement getFieldInput()
Retrieves the field input element associated with this radio button.

Returns:

The field input element.

public LabelElement getLabelElement()
Retrieves the label element associated with this radio button.

Returns:

The label element.

public SmallElement getNoteElement()
Retrieves the note element associated with this radio button.

Returns:

The note element.

public RadioGroup<? super T> getRadioGroup()
Retrieves the radio group to which this radio button belongs.

Returns:

The radio group.

public T withFieldInput(ChildHandler<Radio<T>, DivElement> handler)
Allows customization of the field input element associated with this radio button using a child handler.

handler

The child handler for the field input element.



Returns:

This `Radio` instance.

public T withLabelElement(ChildHandler<Radio<T>, LabelElement> handler)
Allows customization of the label element associated with this radio button using a child handler.

handler

The child handler for the label element.



Returns:

This `Radio` instance.

public T withNoteElement(ChildHandler<Radio<T>, SmallElement> handler)
Allows customization of the note element associated with this radio button using a child handler.

handler

The child handler for the note element.



Returns:

This `Radio` instance.

public T withRadioGroup(ChildHandler<Radio<T>, RadioGroup<? super T>> handler)
Allows customization of the radio group to which this radio button belongs using a child handler.

handler

The child handler for the radio group.



Returns:

This `Radio` instance.

We are a group of passionate people who love what we do

Donate & Support Us