+ Start a Discussion
Jennifer Colbert 1Jennifer Colbert 1 

set a lightning radio button to selected

How do I set a lightning:input radio button to selected? I have a group of radio buttons and I want to programatically set the radio button to selected to match the value in another field on the page in the doInit function of the lightning component. 

There doesn't seem to be a .checked or .selected property that I can set via component.set() code.

Help and guidance appreciated!
Naveen KNNaveen KN
Hi Jennifer, 

Here is the sample code for radio buttons and here we are defaulting to option1

    <aura:attribute name="options" type="List" default="[
    {'label': 'Sales', 'value': 'option1'},
    {'label': 'Force', 'value': 'option2'}
    <aura:attribute name="value" type="String" default="option1"/>

    <lightning:radioGroup name="radioGroup"
                          label="Radio Group"
                          options="{! v.options }"
                          value="{! v.value }"

give default option in the attribute as highlighted above.

In case if your code is totally different then share the code. 

Team codengine.in 
David Roberts 4David Roberts 4
Thanks, Naveen. You helped me.
I'd written the attribute type incorrectly.
<aura:attribute name="value" type="List" default="option1"/>
Once I'd chenged it to String, it worked.