I think this is by design now but in Ember-pre2 i got an jQuery Event passed as paramater to my action handler. the event had a context attribute where the passed context was located.
but now i get the context as parameter and i can't acces the event object anymore.
example:
<div {{action "play" this target="view"}}>{{title}}</div>
MB3.PlaylistView = Ember.View.extend({
play: function(event) {
// how can i access e.g. the currentTarget of the event?
}
});
This is intentional, but something that might be worth supporting.
yeah i supposed so. but how can i solve this? is there a way of doing this at the moment?
if there is no workaround i'll have a look at the code ro see if can make a pull request
@Goltergaul the current "work around" (I would call it a best practice) is to implement a custom view and use click method. The thing is, you should not manipulate DOM elements/events in the controller. Making DOM / JS frontiere more clear is a good thing.
We should either remove target option from action helper or we could passe the event in to the action method if the target is a Ember.View. I think the first one is less confusing.
There is additional discussion here. Like mentioned above a custom view works well and ended up giving us a much cleaner implementation. https://github.com/emberjs/ember.js/issues/1684
@tchak this seems to be a good alternative (to have a click handler). i will have to try that for my problem before i can say if it's a good way. But sounds like a clean solution unless you have to differentiate between to many different targets. I like the idea to route different click actions to different functions. I suppose that was the idea of the action helper?
by the way: i want to have the event information in the view, not in the controller. What i want to do for example is to close an "overlay" when you click in the background. As the background is a parent of the overlay, i need to check the currentTarget to decide whether to close the overlay or not. I realise i can do that in a click handler too. But if i have many such clicks to handle in one function it may get confusing. Do you know what i mean?
if you want this you should implement the click handler. For the overlay case, you may want to consider investigating jQuery special events.
What if we had something like this:
{{action "someClick" on="click" event=true}}
Most helpful comment
What if we had something like this: