0

I have a situation where i have multiple lightning:inputs written inside aura:iteration. I JS controller i am trying to find the input by using Component.find(),but i came to know component.find will not work inside aura:iteration and will return undefined 2 time. So i used event.getSource().

 <aura:iteration items="{!v.customerDocumentsList}" var="customerDocs">
            <div aura:id="StaticDiv" class="slds-box" style="background-color:White;">
                <aura:if isTrue="{!customerDocs.IsDeferredDocument__c == false}">
                    <lightning:layout class="slds-grid--vertical-stretch" horizontalAlign="left" multipleRows="true">
                        <aura:if isTrue="{!or(customerDocs.RecordTypeName__c == 'Deferred',  customerDocs.RecordTypeName__c == 'Invoice' ) }">
                            <lightning:layoutItem  padding="horizontal-small" largeDeviceSize="{!v.lDevice}" mediumDeviceSize="{!v.mDevice}" smallDeviceSize="{!v.sDevice}" size="12">
                                <!--<span style="color:red;" class="required">*</span>-->
                                <lightning:input name ="Invoice no" aura:id="InvoiceNo" label="Invoice no" required="true"
                                                 pattern="^[a-zA-Z0-9_]*$" messageWhenPatternMismatch="Please enter Alphanumeric Values Only"
                                                 value="{!customerDocs.Invoiceno__c}" disabled="{!v.invoicenoMismatch}" />
                                <ui:inputCheckbox label="Invoice Document Missing " value="{!v.invoicenoMismatch}"/>
                            </lightning:layoutItem>
                        </aura:if>

                        <aura:if isTrue="{!or(customerDocs.RecordTypeName__c == 'Deferred',  customerDocs.RecordTypeName__c == 'Invoice' ) }">

                            <lightning:layoutItem padding="horizontal-small"  largeDeviceSize="{!v.lDevice}" mediumDeviceSize="{!v.mDevice}" smallDeviceSize="{!v.sDevice}" size="12"> 
                                <lightning:input name ="Invoice Engine no." aura:id="InvoiceEngineno" required="true" label="Invoice Engine no." pattern="^[a-zA-Z0-9_]*$" messageWhenPatternMismatch="Please enter Alphanumeric Values Only" 
                                                 value="{!customerDocs.InvoiceEngineno__c}" disabled="{!v.invoicenoMismatch}"/>
                            </lightning:layoutItem> 
                        </aura:if>
//JS controller
createDiscrepancy : function(component,event,helper) {
        console.log('fdsaaaaaaaaaaaaa');
        var invoiceChasis = event.getSource();
        var invoiceEngineNo = event.getSource();
        var invoiceNo = event.getSource();

 invoiceEngineNo.reportValidity();
                    invoiceNo.reportValidity();  
                    invoiceChasis.reportValidity(); 

Here still it is giving me error saying invoiceEngineNo.reportValidity() is not a function. I have pasted the code which is only useful not entirely.

I have gone through multiple posts but nothing worked out.Attaching the screenshot of the error. event.getSource() should work here donno what iam doing wrong!!!

Issue solved due to below code changes.

    if(!$A.util.isUndefinedOrNull(invoiceNo)){
                            invoiceNo = helper.fetchAuraCmp(component, invoiceNo);
                            invoiceNoValue = invoiceNo.get("v.value");
                        }
//Helper method
fetchAuraCmp : function(component, cCmp) {
        if(!$A.util.isUndefinedOrNull(cCmp.length) && cCmp.length > 0){
            //invoiceChasisValue = invoiceChasis[0].get("v.value");
            return cCmp[0];
        }
        else if($A.util.isUndefinedOrNull(cCmp.length)){
            //invoiceChasisValue = invoiceChasis.get("v.value");
            return cCmp;
        }
    },

Please help.enter image description here

  • 1
    There's not enough code here to really help you, and you're definitely barking up the wrong tree. component.find should work just fine, as long the DOM is finished rendering. – sfdcfox Nov 16 '18 at 5:54
  • Component.Find() will not work in case of aura:iteration. when lightning input is inside iteration it will not find tts auraLid in 2nd,3rd iterations. However it is now solved. – Deepak Agarwal Nov 16 '18 at 7:11
  • I have checked the length of the data because i was getting array. – Deepak Agarwal Nov 16 '18 at 7:12
  • Changed the code to working one – Deepak Agarwal Nov 16 '18 at 7:14
0

The code is quite ambiguous. There can be many issues. The one that I think is you cannot call a controller method from another method. Try helper methods. To call a helper method use: helper.method(component,event,helper);

  • I am not calling any controller method from another method FYI. Please have a look at code one more time. – Deepak Agarwal Nov 16 '18 at 7:10

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.