Reputation: 756
The objective is to show buttons dynamically on click event. On click of edit button, save and cancel buttons are displayed. On click of cancel button, the edit button should be displayed back which is not working. I am using session in helper.
template.html
<head>
<title>ifelse</title>
</head>
<body>
<h1>Welcome to Meteor!</h1>
{{> hello}}
</body>
<template name="hello">
{{isEdit}}
{{#if isEdit}}
<div class="saveCancelBtnBarLogic">
<button class="button">Save</button>
<button class="cancelEditLogic button">Cancel</button>
</div>
{{else}}
<button class="editDishButtonLogic button">Edit</button>
{{/if}}
</template>
template.js
if (Meteor.isClient) {
Template.hello.events({
"click .editDishButtonLogic": function(event, template) {
console.log("edit true");
Session.set("isEditSession", "true");
}
});
Template.hello.events({
"click .cancelEditLogic": function(event, template) {
console.log("edit false");
Session.set("isEditSession", "false");
}
});
Template.hello.helpers({
isEdit: function() {
console.log("edit helper : " + Session.get("isEditSession"));
return Session.get("isEditSession");
}
});
}
The project is also deployed @ http://ifelse.meteor.com for reference.
Upvotes: 0
Views: 919
Reputation: 756
Resolved:
Changed the below line:
Session.set("isEditSession", "false");
to so:
Session.set("isEditSession", false);
false is a boolean here - notice that false is not in quotes anymore. Thanks to benjick who answered it here @ https://forums.meteor.com/t/if-else-block-in-spacebars-template-not-executing-for-the-second-time/8388/2
Upvotes: 1