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
Pratik KumarPratik Kumar 

component.find() not working with dynamically created lightning components using $A.createComponent()

After creation of components dynamically using $A.createComponent() and pushing it to the desired div, component.find("<aura:ID of component>").get("v.value"), where the component used is a 'lightining:input' and aura:ID has already been defined, is showing error message as 'cannot read property get of undefined'. PFB the code snippet:

 

$A.createComponents([
            ["lightning:input",
             {"aura:ID" : 'fName',
              "name" : 'fName',
              "label" : 'First Name'}],
            ["lightning:input",
             {"aura:ID" : "lName",
              "name" : 'lName',
              "label" : 'Last Name'}],
            ["lightning:input",
             {"aura:ID" : 'mAddress',
              "name" : 'mAddress',
              "label" : 'Mailing Address'}]
        ],function(newDynDiv, status, errorMessage){
            if (status === "SUCCESS"){
                var target = component.find("conForm");
                var body = target.get("v.body");
                body.push(newDynDiv[0], newDynDiv[1], newDynDiv[2]);
                
                target.set("v.body", body); // working fine till here and components are getting added to desired location.
                
                       

           var fVal = component.find("fName").get(v.value); // This shows the error 'cannot read property get of undefined'

            }
            else if (status === "INCOMPLETE") {
                
                alert("No response from server or client is offline.")
                
                // Show offline error
                
            }
            
                else if (status === "ERROR") {
                    
                    alert("Error: " + errorMessage);
                    
                    // Show error message
                    
                }
            
        });

Pratha JGPratha JG
Hello Pratik, 

Any luck? We are also experiencing this issue after Spring '18 release. :(
Anže KovačAnže Kovač
Hi Pratik, did you find solution to this problem ?