ons-radio

A radio button element. The component will automatically render as a Material Design radio button on Android devices. Most attributes that can be used for a normal <input type="radio"> element can also be used on the <ons-radio> element.

Tutorial

Radio buttons

Radio buttons are defined using the <ons-radio> element.

<ons-radio checked></ons-radio>

To create a group of radio buttons the name attribute is used:

<ons-radio name="group" value="first"></ons-radio>
<ons-radio name="group" value="second"></ons-radio>

This will enable switching between radio buttons.

Inner input element

For normal input elements is possible to define a <label> tab with the for attribute to link it to an input element.

Unfortunately this does not work with custom elements like <ons-label> so in order to do it we need to set the id attribute of the inner input element. This is done using the input-id attribute.

<label for="username">Username</label>
<ons-input input-id="username"></ons-input>

This work with any input in Onsen UI such as checkboxes, radios, etc.

See also

Attributes are added directly to the element. You can do this in HTML or JS.

HTML: <ons-radio someAttribute="true" anotherAttribute><ons-radio>
JS: document.querySelector('ons-radio').setAttribute('someAttribute', 'true')

Name Type Description
input-id String Specify the “id” attribute of the inner <input> element. This is useful when using <label for="..."> elements. Optional.

Properties are accessed on the element through JS, and should be get and set directly. For example: document.querySelector('ons-radio').value.

Name Description
value The current value of the radio button.
checked Whether the radio button is checked or not.
disabled Whether the radio button is disabled or not.

Modifiers are set in the modifier attribute. To use more than one, separate them by spaces. For example:
<ons-radio modifier="material modifier2"><ons-radio>.

Name Description
material Displays a Material Design radio button.

These methods are called directly on the DOM element. Get a reference to the element in JS, and the methods below will be available to call on it. For example: document.querySelector('ons-radio').someMethod().

Signature Description
focus() Focuses the radio button.
blur() Removes focus from the radio button.
focus()

Focuses the radio button.

blur()

Removes focus from the radio button.

Need Help?

If you have any questions, use our Community Forum or talk to us on Discord chat. The Onsen UI team and your peers in the community will work together to help solve your issues.

For bug reports and feature requests use our GitHub Issues page.