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
DML2020DML2020 

Enter Key search method not firing

We have a search field that will render results on two actions: clicking a 'Search' button and hitting the 'Enter' key. At present, we can only get results when the button is pressed. When the 'Enter' key is hit, nothing fires (no activity seen via console log on Inspect)

The following shows code in the controller

KeyPresssearch: function(component, event, helper) {
    if (event.which == 13) {
      this.search(component, event, helper);
    }
 

and 

search: function(component, event, helper) {
    component.set("v.pageNumber", 1);
    component.set("v.filterStartWith",'');
 
      var showMembersOnly = component.get("v.showMembersOnly");
      var AccountViewComponent;
      if (showMembersOnly){
      AccountViewComponent = component.find("memberView");
      } else {
      AccountViewComponent = component.find("allView");
      }
     
      AccountViewComponent.searchCompanies(component.get("v.searchValue"));
  }
 

What do you recommend I check to troubleshoot this?

Suraj Tripathi 47Suraj Tripathi 47

Hi DML2020,

Answer

var isEnterKey = event.keyCode === 13;
if(isEnterKey){
     //your code/method will be here
}


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

Thanks and Regards,
Suraj Tripathi