0

Is it okay to have two identical aura:ids when only one of them is shown at a time? Will there be any problems accessing the shown input using the component.find?

   <aura:if isTrue="{!(v.currentFlow == 'ACTIVATION')}">
       <p><lightning:input type="date" aura:id="ActivationDate" label="{!$Label.c.enterActivationDate}"/></p>
   </aura:if>

   <aura:if isTrue="{!(v.currentFlow != 'ACTIVATION')}">
       <p><lightning:input type="date" aura:id="ActivationDate" label="{!$Label.c.enterActivationDate}"/></p>
   </aura:if>
2

Yes, this is allowed. Component's find will return either undefined (no values), an object (one value), or a list (two or more values). There's a small bug that I'm not sure was ever fixed where changing multiple items like this might result in find returning a list consisting of a single element, so you may need to prepare for that by checking if there's a length attribute before using the results from find.

|improve this answer|||||

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.