1

I have the following code to generate a group of radio buttons. I can't seem to retrieve the value of the selected item. Thoughts?

Component:

                             <aura:iteration items="{! v.registrationOptions2 }" var="item">
                                <input type="radio"
                                       aura:id="amountDueRadioButton"
                                       id="terms" 
                                       name="terms" 
                                       onchange="{!c.calculateRegistrationAmountDue}"                       
                                       value="{!v.registrationSelection}">
                                </input>
                                <label for="terms"><aura:unescapedHtml value="{!item.label}" /></label><br/>
                            </aura:iteration>

<aura:attribute name="registrationOptions2" type="List" 
                default="[
                         {'label': '&nbsp;Open Day ($375)', 'value': 'Open Day'},
                         {'label': '&nbsp;Open Day + &lt;i&gt; Improving Stability of Biological Products&lt;/i&gt; Technical Workshop ($375 + $75)', 'value': 'Open Day + Workshop'},
                         {'label': '&nbsp;&lt;i&gt;Improving Stability of Biological Products&lt;/i&gt; Technical Workshop ONLY ($200)', 'value': 'Workshop ONLY'}                                                 ]"/>                                

Controller:

calculateRegistrationAmountDue: function(component, event, helper) {
         var registrationOption = event.getSource().get("v.value");
1

1 Answer 1

0

The link in the comment above is good, but you have another problem that will cause issues.

You need to set the value from the iteration variable, not from an attribute.

Like this:

<aura:iteration items="{! v.registrationOptions2 }" var="item">
  <lightning:input type="radio" 
                 value="{!item.val}" 
                 label="{!item.label}"   
                 name="terms" 
                 onchange="{!c.calculateRegistrationAmountDue}" />
</aura:iteration>

This will mean that when you retrieve the event source value, it'll be selected/unselected as you expect.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .