Toggle checkbox page
Toggle a todo’s completed state (event bindings)
The problem
- Call
toggleComplete
when a todo’s checkbox is clicked upon.
What you need to know
The can-stache-bindings Presentation’s up to and including DOM Event Bindings
Use on:EVENT to listen to an event on an element and call a method in
can-stache
. For example, the following callsdoSomething()
when the<div>
is clicked.<div on:click="doSomething()"> ... </div>
The solution
Click to see the solution
Update index.stache to the following:
<!-- index.stache -->
<section id="todoapp">
<header id="header">
<h1>{{ this.appName }}</h1>
<input id="new-todo" placeholder="What needs to be done?">
</header>
<section id="main" class="">
<input id="toggle-all" type="checkbox">
<label for="toggle-all">Mark all as complete</label>
<ul id="todo-list">
{{# for(todo of this.todosList) }}
<li class="todo {{# if(todo.complete) }}completed{{/ if }}">
<div class="view">
<input class="toggle" type="checkbox"
{{# if(todo.complete) }}checked{{/ if }}
on:click="todo.toggleComplete()" />
<label>{{ todo.name }}</label>
<button class="destroy"></button>
</div>
<input class="edit" type="text" value="{{ todo.name }}" />
</li>
{{/ for }}
</ul>
</section>
<footer id="footer" class="">
<span id="todo-count">
<strong>{{ this.todosList.active.length }}</strong> items left
</span>
<ul id="filters">
<li>
<a class="selected" href="#!">All</a>
</li>
<li>
<a href="#!active">Active</a>
</li>
<li>
<a href="#!completed">Completed</a>
</li>
</ul>
<button id="clear-completed">
Clear completed ({{ this.todosList.complete.length }})
</button>
</footer>
</section>