function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
abhishek_pandey1989@yahoo.comabhishek_pandey1989@yahoo.com 

Dynamic ids not getting created in lightning component

Hi Need quck help if possible, 

Created below modal and tried to iterate a list and created dynamic ids on the modal components, but after pressing button on modal , the find function on lightning controller always says "undefined" value for dynamic ids are just created on modal , I can see other values in modal getting iterated perfectly. 

Modal Code------------------------------------------------------------------>

<div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                                <aura:iteration items="{!v.fileToBeUploaded}" var="fileDetails">
                                    <lightning:input aura:id="{!'fileName------'+fileDetails.documentId}" value="{!fileDetails.name}" required="true" name="input1" label="Confirm the file name" ></lightning:input>
                                    <lightning:select aura:id="{!'fileAttach-----'+fileDetails.documentId}" name="a_opt" label="Podklady Typ">
                                        <aura:iteration items="{!v.podklady}" var="pdkL">
                                            <option value="{!pdkL.idVal}">{!pdkL.idVal}</option>
                                        </aura:iteration>
                                    </lightning:select>
                                </aura:iteration>
                            </div>
                            <footer class="slds-modal__footer">
                                <lightning:button variant="neutral"
                                                  label="Cancel"
                                                  title="Cancel"
                                                  onclick="{! c.closeModel }"/>
                                <lightning:button variant="brand"
                                                  label="OK"
                                                  title="OK"
                                                  onclick="{!c.submitDetails}"/>
                            </footer>


Lightning Js controller code -------------------------------------------------->
var uploadedFiles = component.get("v.fileToBeUploaded");
for(var i=0; i< uploadedFiles.length; i++){
console.log(component.find('fileName------'+uploadedFiles[i].documentId).get("v.value"));
}
Deepali KulshresthaDeepali Kulshrestha
Hi Abhishek,

I went through the query of yours and found aura: id doesn’t support expressions. You can only assign literal string values to aura: id. The alternative to this is to dynamically create the component using $A.createComponent and since the attribute is accessible via the JavaScript one can assign dynamic values to aura: Id Currently the expression syntax is not supported in the aura: id attribute.

Please refer to the following links as they might be helpful in solving your query:
https://success.salesforce.com/ideaView?id=0873A000000E8fBQAS

https://bugcoder.it/?p=174
https://salesforce.stackexchange.com/questions/154416/lightning-components-can-auraid-be-set-to-an-component-attribute

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.
Sai Sasidhar BhagavathulaSai Sasidhar Bhagavathula
Can't we fetch the id dynamically from component ? Could you please assist on the same as I need to go with the above approach rather using Create Component methodology.

Thanks in Advance!