I want to save the radio button(lightning component) value in salesforce. I am unable to do so.

When i try to select any one of the radio button error says resultCmp.set is not a function.

Here is my code:


     <aura:attribute name="pollQuestionObj" type="LghtCompNS__Poll_Question__c" default="{'sobjectType': 'LghtCompNS__Poll_Question__c'}"/>
     <aura:attribute name="visibleTo" type="String[]"    default="Admin,Everyone"/>
      <div style="margin-left: 5px;" class="slds">
  <p class="slds-page-header pollingTitle" role="banner">Add Poll Question</p>
      <ui:inputText label="Question" class="slds-input" aura:id="question" placeholder="Enter Poll Question" value="  {!v.pollQuestionObj.LghtCompNS__Poll_Question__c}" required="true"/>
     <ui:inputDate aura:id="startDt" class="slds-input" label="Start Date" value="{!v.pollQuestionObj.LghtCompNS__Start_Date__c}" displayDatePicker="true" />
     <ui:inputDate aura:id="endDt" class="slds-input" label="End Date" value="{!v.pollQuestionObj.LghtCompNS__End_Date__c}" displayDatePicker="true" />
     <ui:inputDate aura:id="resultVisibleDt" class="slds-input" label="Result Visible From Date" value="{!v.pollQuestionObj.LghtCompNS__Result_Visible_From_Date__c}" displayDatePicker="true" />
     <aura:iteration items="{!v.visibleTo}" var="stage">
        <ui:inputRadio label="{!stage}" name="visibleT" aura:id="visibleT" change="c.visibleToUser" value=""/>

     <div class="submitBtn">
        <ui:button label="Submit" press="{!c.addQuestion}" class="btn btn-default btn-lg btn-block"/>


 visibleToUser : function(component, event, helper) {
    var elem = event.getSource().getElement();
    var selected = elem.textContent;
    resultCmp = component.find("visibleT");        
    resultCmp.set("v.value", selected);

If you don't already have one, you would need a client-side controller (javascript) that basically invokes the getVisibleToDetails() method in your apex controller and gets the results to display them on the lightning component page.

Invoke the client side code on initialization: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cb_init_handler.htm

Writing the client-side controller code: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_client_side_controller.htm

Please share the client-side controller code if you have it which would help better answer your question.

Also, assuming you do have a cient-side controller, how are you populating the attribute pollQuestionObj? You are returning a List of LghtCompNS__Poll_Question__c from your apex method, but your attribute is of type LghtCompNS__Poll_Question__c and not of type List or Array [].

Try this:

<aura:attribute name="pollQuestionObj" type="LghtCompNS__Poll_Question__c[]" />

<aura:iteration items="{!v.pollQuestionObj}" var="pollOptionItem">
    <label class="radio-inline">                        
        <input type="radio" id="{!pollOptionItem.Id}" name="response" onchange="{!c.visibleToUser}"/>
  • thnx for your quick reply. I have change some logic so please go through the question again and revert if possible. – Ejaz Apr 21 '16 at 19:17
  • You already have the value of the radio button in the 'selected' variable. Why do you need to save it again and where? What do you plan to do with this value? Looks like you're trying to update (set) the same component - what is the purpose of resultCmp? – Kedar Joshi Apr 21 '16 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.