Instead of selecting an item first and then using a button to perform some action on the selected item I would prefer for the user to perform one click.
It seems to work but I have concerns that the event on the button must occur after the event on the carpool_event. This just doesn’t seem right. Is there a better way to handle this? Thanks!
in my HTML
<template name="carpool_list">
<h1>Carpool</h1>
{{#each carpool_events}}
<ul>
{{> carpool_event}}
</ul>
{{else}}
No events yet.
{{/each}}
</template>
<template name="carpool_event">
<div class="carpool_event">
<span class="localDate">{{localDate}}</span>
<span class="owner">{{owner}}</span>
{{#if currentUser}}
<span><input type="button" class="takeEvent" value="Take Event"/></span>
{{/if}}
</div>
</template>
corresponding js
Template.carpool_event.events({
'click': function () {
Session.set("selected_carpool_event", this._id);
}
});
Template.carpool_list.events({
/**
* Take Event Handler
*/
'click .takeEvent': function () {
console.log("Take event:"+Session.get("selected_carpool_event"));
}
});
You could try this:
or if you want both clicks for some other reason or you can avoid having capturing the first click you could target the button directly,
this._idshould work on the button too (you can assign a handler to the same templatecarpool_eventfor a button anywhere inside the template)