1

Currently, I'm iterating through a wrapper that includes sourceId (aka accountId) and Opportunity Name, etc. When the user selects a radio button, I want to capture that sourceId in an attribute at the top of my component called "accountId".

    selectAccountRadioGroupOnChange : function(component, event, helper) {
    helper.setAccountId(component, helper);
}

The JS Helper is attempting to get the value attribute on the specific Radio Button that was selected.

    setAccountId : function(component, helper) {
    console.log(component);
    var accountIdOnRadioButton =  component.get("v.selectAccountRadioGroup");    
    component.set('v.accountId', accountIdOnRadioButton); 
    console.log('accountIdOnRadioButton', accountIdOnRadioButton);
}

You can see the console.log returns 'undefined' enter image description here

<aura:component access="public" implements="force:appHostable,lightning:isUrlAddressable" controller="MyController">    
<!--<aura:attribute name="organizationWrappers" type="List" default=""/>-->
<aura:attribute name="compositeWrapper" type="Object" />  
<aura:attribute name="options" type="List" default="[{'label': '', 'value': 'option1'}]"/>
<aura:attribute name="value" type="String"/>
<aura:attribute name="accountId" type="String"/>

Note I'm trying to set value here to {!organization.sourceId}, which is the Account ID. This would allow me to then get that Account Id later. (Also, note here: onchange="{!c.selectAccountRadioGroupOnChange}")

    <tbody>
        <aura:iteration items="{!v.compositeWrapper.organizations}" var="organization">
            <tr>
                <td scope="row">
                    <lightning:radioGroup name="selectAccountRadioGroup"
                        onchange="{!c.selectAccountRadioGroupOnChange}"
                        variant="label-hidden"
                        options="{!v.options}"
                        value="{!organization.sourceId}"
                        type="radio"
                    />
                    <!--accountId = "{!organization.sourceId}"-->
                </td>
                <td>{!organization.organizationName}</td>                      
                <td>
                    <lightning:formattedDateTime value="{!organization.lastPurchaseDate}"/>
                </td>
  • selectAccountRadioGroupOnChange.js can you share its code – User6670 Feb 12 at 20:32
  • Thanks @User6670, I just added it to the body here. – Ryan McNeely Feb 12 at 20:40
  • why are you using lightning radio group you can just use lightning input of type radio – User6670 Feb 12 at 21:00
2

component

 <aura:component>
    <aura:attribute name="options1" type="List" default="['1','2','3']"/>
    <aura:attribute name="options" type="List" default="[{'label': '', 'value': 'option1'}]"/>
    <aura:attribute name="value" type="String" default="option1"/>
 <aura:iteration items="{!v.options1}" var="organization">
     <input type="radio" id="{!organization}" name="options"  onclick="{!c.checkboxSelect}"  />
    </aura:iteration>
</aura:component>
}

and in js

checkboxSelect: function(component, event, helper) {
   var selectedaccId= document.querySelector('input[name="options"]:checked').id;
console.log(selectedaccId);


}
| improve this answer | |
  • Thanks @User6670, I just tried as you advised and got the following: This page has an error. You might just need to refresh it. Action failed: c:mycomponent$controller$selectAccountRadioGroupOnChange [event.getSource is not a function] Failing descriptor: {c:mycomponent$controller$selectAccountRadioGroupOnChange} – Ryan McNeely Feb 12 at 21:09
  • did you pass the event? – User6670 Feb 12 at 21:12
  • Also, can I even assign radioButtonGroup with value="{!organization.sourceId}"? Is there another way to store this bit of data per Iteration? – Ryan McNeely Feb 12 at 21:18
  • yes, I passed the event – Ryan McNeely Feb 12 at 21:25
  • selectAccountRadioGroupOnChange : function(component, event, helper) { helper.setAccountId(component, event, helper); } – Ryan McNeely Feb 12 at 21:25

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.