Reputation: 11786
How to write "escape-press" action in a more HTML format than {{input escape-press='alertUser'}}
.
I have some inputs defined like that <input type="text" name="item-name" value={{item.name}} onblur={{action "confirmName" value="target.value"}} />
and I would like to keep this syntax.
Upvotes: 0
Views: 252
Reputation: 1281
It's exactly the same you do with onblur
. In your template, you associate an action to the event onkeypress
like this:
<input type="text" onkeypress={{action 'escape'}}>
and then, in your controller or component, you add an action to handle it:
actions:{
escape(e){
if(e.key === 'Escape'){
//your code here
}
}
}
Upvotes: 1