emberjs/ember.js — pull request #926 by joliss (2012-05-31 21:54:19+00:00)
Title: Call preventDefault and stopPropagation on events handled through {{action}}

The idea is that we'd like to be able to use arbitrary view methods as
action handlers. As it is, they need to `return false` or call
`e.preventDefault(); e.stopPropagation();` to be usable as handlers.

For the (presumably few) cases where propagation or default handling is
desired, we can still register our own handlers/delegates with jQuery,
or use event handling on views or with eventManagers, which does not
have automatic preventDefault/stopPropagation.

----------------------

I realize this change is potentially invasive, so I'm targeting it at master, not 0-9-stable.

What do you guys think?

Also, can someone with a larger Ember app please test this and report back whether it breaks things?

Cc @ebryn, who introduced the test I'm changing.

IRC discussion:

```
[9:29pm] joliss: I'm bothered by the fact that all of my {{action}} handlers have to call `e.preventDefault(); e.stopPropagation()`. It means I can't just call arbitrary methods on my views as actions. Is there anything that's fundamentally stopping us from changing it to do this automatically?
[9:31pm] michaellatta: joliss: returning false from click events seems to be sufficient in the experimenting I have done to date.
[9:31pm] joliss: michaellatta: Right, unless they throw an exception though. And it's still the same problem, with fewer characters.
[9:39pm] joliss: Hm, there used to be an automatic stopProgagation, but dmarcotte changed it in 6e2d3515. I'm not sure why.
(Note: This actually seems to be a different one, relating to event methods like `doubleClick`, not action handlers.)
[9:42pm] knassar: joliss: i am a bit bothered by the same thing
[9:43pm] peterwagenet: joliss: automatic stop propagation wasn't well implemented
[9:43pm] knassar: seems like the 90% case is that you don't want the events to propagate…
[9:43pm] peterwagenet: if anyone has a solution for normalizing that seems fine
[9:43pm] joliss: peterwagenet: Can you elaborate what the issue was?
[9:44pm] peterwagenet: inconsistent
[9:44pm] joliss: Looking at the diff, I'm just thinking preventDefault should be called as well, and it should be called *before* calling the handler.
[9:45pm] joliss: Hm, you mean there were cases (other events?) where it *didn't* stop propagation?
[9:57pm] endash: man there are certainly states where I'd like to ensure the end of propogation.
[10:32pm] joliss: peterwagenet: ping; before I submit a pull request, do you happen to remember what the issue with stopping event propagation was?
[10:33pm] peterwagenet: we weren't doing it across the board
[10:33pm] peterwagenet: so it only worked some places
[10:33pm] peterwagenet: and not others
```