[SalesForce] How to implement ui:inpuText Enter key event in Lightning

How can i implement uiLinpuText Enter key Event in Lightning? what i want is when the user done inputing a value into a lightning textbox the (ui:inputText) , the user will just press the enter key in the keyboard and will execute a client side controller function().

HERE IS MY CODE

LIGHTNING COMPONENT

 <input aura:id="textsearch" 
        type="text" 
        name="default" 
        placeholder="Search Events..." 
        onkeyup="{!c.searchEvents}" 
        class="size-full ht-44 plm prx pvm input input--default input--ph-1 input--focus-1" />

CLIENT SIDE CONTROLLER

searchEvents: function(component, event, helper) {
    alert('Entered');
}

Best Answer

You can get the keyCode from the event object .Below is what I tried and worked

({
  searchEvents: function(component, event, helper) {
      console.log(event.getParams().keyCode);
      if(event.getParams().keyCode == 13){
        alert('Enter key pressed');
      }
   }
 })

You can also use which as well .Below is the console.log of whole event object

enter image description here

Related Topic