Ember.js: key-press action on {{input}} has no access to event

Created on 1 Dec 2015  路  10Comments  路  Source: emberjs/ember.js

key-up and other pass event object as second argument to the action handler, but not key-press.

demo: https://ember-twiddle.com/f06db4499c0c2806c5a3

Most helpful comment

In the following snippet, the someThing action will be called with the event...

<input value={{foo}} oninput={{action 'someThing'}}>

All 10 comments

@ruz to handle keyboard events and access the event object using an event handler instead of an action should work, see - http://guides.emberjs.com/v2.2.0/components/handling-events/

I think that actions are not expected to pass any event object.

Bug report is not about how, but that it's not consistent :(

@ruz, no way to acess event object in keypress, also focusin/focusout. You need to use keyUp/keyDown instead. From the source code, keyPress is using a specific sendAction function wrote for {{action 'xxx' on=""}} and call another sendAction function used in keyUp/keyDown with sending input element's value before entering new charactor only. Yep, event object at all... No idea why they did this. I sent a pull request to fix this, but I'm not sure whether it will be proved or not.

@JennieJi back you up on this

@nightire Thank you Albert :)

Thanks all. I expect when we write a glimmer version of the input helper we can change the arguments being passed and make them more consistent.

However we're not interested in making this change. It perpetuates inconsistencies about when and where the event object is passed as well as adding more jquery to our API. We're attempting to move away from passing jquery events around, instead of adding more in.

Please update documentation. I spent quite a while trying to use {{input}} helper with event handler via helper arguments. It was so frustrating, annoying and time consuming experience.

In the following snippet, the someThing action will be called with the event...

<input value={{foo}} oninput={{action 'someThing'}}>

The same issue exists with focusOut. I just had an instance where I needed to know which element caused focusOut from input and the event was not being passed through.

Seems related to null-null-null/ember-keyboard#56

Was this page helpful?
0 / 5 - 0 ratings