Reputation: 395
I have a checkbox implemented and it's working just fine.
HTML:
<form>
<ul>
{{#each checkbox}}
<li>
<input type="checkbox" checked="{{checked}}" class="toggle-checked"> {{name}}: {{checked}}
</li>
{{/each}}
</ul>
</form>
JS:
Cbtest = new Mongo.Collection('cbtest');
Template.checkbox.helpers({
checkbox: function () {
return Cbtest.find();
}
});
Template.checkbox.events({
"click .toggle-checked": function () {
var self = this;
Meteor.call("setChecked", self._id, !self.checked);
}
});
Meteor.methods({
setChecked: function (checkboxId, setChecked) {
Cbtest.update(checkboxId, {
$set: {
checked: setChecked
}
});
}
});
I want to display the Value ("true" or "false") depending on the checkbox's state. As now it seems that the Expression "{{ checked }}" is evaluatiated to true or false, and if its true then it returns the value of the corresponding document entry. How can i just display the content as String ("true" / "false")?
Thanks in advance! Vin
Upvotes: 0
Views: 502
Reputation: 789
You could add another helper that transforms the checked
Bool into a String using the toString()
function:
checkedString: function () {
return this.checked.toString();
}
And then use this helper in the template:
<input type="checkbox" checked="{{checked}}" class="toggle-checked"> {{name}}: {{checkedString}}
See this meteor pad for a demo.
Upvotes: 1