+ Start a Discussion
Sai Subhash 6Sai Subhash 6 

How can i save a selected radio button value into field using Lightning component

Selected radio button value save to field and update the record

I tried this
Component:

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction">
 <fieldset class="slds-form-element">
     <div class="slds-form-element__control">
        <div class="slds-radio_button-group">
            <legend class="slds-form-element__legend slds-form-element__label">Please Rate Technician</legend><br/>
            <ui:inputRadio text="1" label="1" name="Role" change="{!c.onGroup}"/>
            <ui:inputRadio text="2" label="2" name="Role" change="{!c.onGroup}"/>
            <ui:inputRadio text="3" label="3" name="Role" change="{!c.onGroup}"/>
            <ui:inputRadio text="4" label="4" name="Role" change="{!c.onGroup}"/>
            <ui:inputRadio text="5" label="5" name="Role" change="{!c.onGroup}"/>
        </div>
     </div>
 </fieldset>
</aura:component>

Controller:
({
    onGroup: function(cmp, evt) {
        var selected = evt.getSource().get("v.text");
        //alert(selected);
    }

})
Ashwin Kumar SrinivasanAshwin Kumar Srinivasan
you can try using LDS to update or create the record with the value you get out of the inputRadio. please refer this https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service.htm
GhanshyamChoudhariGhanshyamChoudhari
on which object and which field you want to store the radio button data? 
Anil SomasundaranAnil Somasundaran

@Sai Subhash 6

I am not sure if you are looking for this.

We can update a field in two ways 

1. using an attribute

In component
<aura:attribute name="selection" type="String" default=""/>
    <ui:inputRadio text="1" label="1" name="Role" change="{!c.onGroup}"/>
    <ui:inputRadio text="2" label="2" name="Role" change="{!c.onGroup}" />
     <ui:inputRadio text="3" label="3" name="Role" change="{!c.onGroup}"/>
     <ui:inputRadio text="4" label="4" name="Role" change="{!c.onGroup}"/>
     <ui:inputRadio text="5" label="5" name="Role" change="{!c.onGroup}"/>
    
    <ui:outputText class="result" aura:id="result" value="{!v.selection}" />

In Js Controller
onGroup : function (component, event, helper) {
        var selected = event.getSource().get("v.text");
        component.set("v.selection",selected);
    }

2 using aura:id

In Component Part of aura bundle
<ui:inputRadio text="1" label="1" name="Role" change="{!c.onGroup}"/>
<ui:inputRadio text="2" label="2" name="Role" change="{!c.onGroup}" />
<ui:inputRadio text="3" label="3" name="Role" change="{!c.onGroup}"/>
<ui:inputRadio text="4" label="4" name="Role" change="{!c.onGroup}"/>
<ui:inputRadio text="5" label="5" name="Role" change="{!c.onGroup}"/>
    
<ui:outputText class="result" aura:id="result"  />

In JS controller
 
onGroup : function (component, event, helper) {
        var selected = event.getSource().get("v.text");
        component.find("result").set("v.value",selected);
 }


Please mark this as best answer if your query has been resolved. Visit my blog to find more about lightning https://techevangel.com/author/anilsomasundaran/