<aura:iteration items="{!v.userCustomFieldSet}" var="fieldSet" indexVar="i"> <ui:inputText value="{!fieldSet.FieldValue}" aura:id="{!fieldSet.FieldName}"/> </aura:iteration>

Above code, Getting Error when i'm accessing the field-set Cannot read property 'getElement' of undefined

  • You cannot assign auraid’s dynamically – glls Jul 23 '18 at 12:15
  • I think that here you can find solution of your problem. – Ewa Latoszek Jul 23 '18 at 12:17

Like glls pointed out, dynamic aura:ids are not supported (yet). It will be helpful to know what your end goal is so we can make an effective recommendation. Did you know that if you set the aura:id to a static value like: aura:id="myInput", you can get the values in ControllerJS by doing: component.find("myInput").get("v.value")? That will work as long as there is precisely ONE matching aura:id in the component. But in your case there will be multiple because of aura:iteration, so component.find("myInput") will return an array of all matching elements you can easily loop through.

| improve this answer | |

As mentioned in by @glls in the comment and @Kal answer - You cannot assign auraid’s dynamically, instead you can use the element's id via document.getElementById:

<aura:iteration items="{!v.userCustomFieldSet}" var="fieldSet" indexVar="i"> 
     <ui:inputText value="{!fieldSet.FieldValue}" id="{!fieldSet.FieldName}"/> 

and in you controller get the element like this:

var fieldName = document.getElementById('fieldName');

I got help on this from an answer that @sfdcfox gave me here:

component.find an aura:id item created in aura:iteration

| 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.