Search code examples
meteorspacebars

How can I listen to one event from two template handlers?


For instance in the below, only the foo event handler is called. (Which is odd – I would have expected the bar event handler to be called, since the <form> element is in the bar template.)

<template name="foo">
  {{#bar klass="down"}}
    <button type="submit">test</button>
  {{/bar}}
</template>

<template name="bar">
  <form>
    {{> Template.contentBlock}}
  </form>
</template>

Template.foo.events 
  'submit form' ->
    alert 'foo'

Template.bar.events 
  'submit form' ->
    alert 'bar'

Solution

  • The answer of how to do so is the code in the question, which in fact works as desired. The bar handler is called, followed by the foo handler.

    http://meteorpad.com/pad/kLwjq8N7T5fb2qwjA/event%20bubbling