Currently I am using an <lightning:input>
with an onkeypress
listener.
Everything is ok, but it applies whole component. For example I press 'enter'. I didn't write this code but it execute this function.
Moreover, when I typed nothing on <lightning:input>
but just press 'enter'
it causes an error on the other component:
[Cannot read property 'setParams' of undefined]
I just want to apply current component 'enter' key search, not in all components. What am I doing wrong? How can I fix it?
Markup
<lightning:input aura:id="dptCode" onchange="{!c.handleBlur}" updateOn="keyup" onkeypress="{!c.keyPressed}" maxlength="20"/>
Controller
keyPressed : function(component,event,helper){
document.addEventListener('keypress', function(e){
if(e.keyCode==13){
helper.handlerSearchEnterEvt(component,event,helper);
}
},true)
}