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
shaik israhshaik israh 

Cannot read property 'value' of undefined

Hi Team,
I am creating ContactSearchBar and ContactList as single component. On initialization of component am loading all the contacts to list after  in serach bar if i type any charachter am getting "Cannot read property 'value' of undefined"  error.Please find my snippet code
({
	doInit : function(component, event, helper) {
		  var action = component.get("c.findAllContactsList");
          action.setCallback(this, function(a) {
            component.set("v.Accounts", a.getReturnValue());
        });
        $A.enqueueAction(action);
	},
    ContactNameSearchKeyChange: function(component, event, helper) {
        var myEvent = $A.get("e.c:ContactSearchKeyEvent");
         
        myEvent.setParams({"searchKey": event.target.value});
        myEvent.fire();
          
    },
  
    ContactNameSearchKeyChange: function(component, event) {
    var searchKey = event.getParam("searchKey");
    var action = component.get("c.findByContactName");
    action.setParams({
      "searchKey": searchKey
    });
    action.setCallback(this, function(a) {
        component.set("v.contacts", a.getReturnValue());
    });
    $A.enqueueAction(action);
}
})

 
Veena Sundara-HeraguVeena Sundara-Heragu
You have 2 controller methods with the same name "ContactNameSearchKeyChange".  
NK@BITNK@BIT
Suraj Tripathi 47Suraj Tripathi 47
Hi Shaik Israh
You have define same method for 2 time. This will call only one function.
You can follow the below code:-
({
	doInit : function(component, event, helper) {
		  var action = component.get("c.findAllContactsList");
          action.setCallback(this, function(a) {
            component.set("v.Accounts", a.getReturnValue());
        });
        $A.enqueueAction(action);
	},
  
    ContactNameSearchKeyChange: function(component, event) {
    var searchKey = event.target.value;
    var action = component.get("c.findByContactName");
    action.setParams({
      "searchKey": searchKey
    });
    action.setCallback(this, function(a) {
        component.set("v.contacts", a.getReturnValue());
    });
    $A.enqueueAction(action);
}
})
Also if this not work you can do thebelow steps:-
1. create aura attribute and assign the search field value in that attribute.
2. Then replace "var searchKey = event.target.value" with 'var searchKey = component.get("v.yourAttributeName")'.

If you face any problem then post it.
Please mark it as best answer if it helps you to fix the issue.

Thank you!

Regards,
Suraj Tripathi