iron-meteor / iron-router

A client and server side router designed specifically for Meteor.
MIT License
1.98k stars 413 forks source link

Events in yielded regions #1535

Open betacar opened 8 years ago

betacar commented 8 years ago

So, I have a couple of regions in my default layout that look like this:

  <div class="title_left">
    <h3>{{> yield "pageTitle"}}</h3>
  </div>

  <div class="title_right">
    {{> yield "pageOptions"}}
  </div>

In the page pageOptions region, I'm passing a block that contains two buttons:

<template name="myView">
  {{#contentFor region="pageOptions" incident=incident that=this}}
    <div class="col-md-7 col-sm-7 col-xs-12 pull-right text-right">
      <button data-action="open" class="btn btn-sm btn-default setAction">
        Set as open
      </button>

      <button data-action="closed" class="btn btn-sm btn-default setAction">
        Set as closed
      </button>

      <a href="#" class="btn btn-default btn-sm">Back</a>
    </div>
  {{/contentFor}}
</template>

Both buttons have an onClick event associated:

Template.myView.events
  'click .statusSelect': (evnt, tmpl) ->
    action = evnt.target.getAttribute 'data-action'
    {_id} = tmpl.data
    selector = _id or null
    MyCollection.update _id, $set: {action}

However, when these buttons are inside the {{contentFor}} block, the event listeners are deafs. I may be wrong on this, but maybe the template context changes when from one block to the other.

So, my question is, how can I keep the context of the myTemplate template inside the pageOptions region? Or, if it is possible, how can I pass the event listeners to region?

Here are the packages I'm using: