8

I have a lightning:radioGroup that shows record types for an object:

<aura:attribute name="recordTypes" type="String[]"/>
<aura:attribute name="recordTypeValue" type="String"/>

<lightning:radioGroup options="{!v.recordTypes}" value="{!v.recordTypeValue}" required="true"/>

In my controller I populate the recordTypes list with unique label-value pairs.

The radio buttons and their labels show up nicely. However, suddenly they become multi-selectable:

  • select option1 > select option2 > select option1 (now both options are selected)

When I debug recordTypeValue I can see 2 Ids written into it. I am not seeing any attributes on the said component that allows me to enable/disable multi-selecting.

11

You've forgotten a required attribute. The radioGroup is grounded in HTML's <input type="radio" />, which uses a "name" attribute to determine groups. If you forget to specify the name, the options actually behave like independent radio groups. The following change is necessary for proper operation:

<lightning:radioGroup name="recordTypes" options="{!v.recordTypes}" value="{!v.recordTypeValue}" required="true" />

Where "name" should be unique to each lightning:radioGroup within the component.

Note: The documentation lists "name" as optional; this is clearly a developer/documentation oversight, because without a name, this component won't work as expected.

  • That solved it! But I don't get why going from option1 to option2 worked (i.e. option1 was deselected).. – Mossi Feb 8 '18 at 22:24
  • @Mossi Might have been your browser. When I tried it, going from option1 to option2 resulted in both being selected. – sfdcfox Feb 8 '18 at 22:24

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.