I have a scenario where the Click event is bind to <tr>
and checked value is bind to checkbox inside the <td?
inside <tr>
. Now the problem is When the row is clicked the event is fired thats fine . But in case of I click the checkbox the observable value changes for row as well and fires the row click event . How to avoid this scenario
<tbody data-bind="foreach:Mails">
<tr data-bind="click:$root.navigateToMail">
<td style="width: 15px">
<input type="checkbox" data-bind="checked: isSelected">
@*<input type="checkbox">*@
</td>
<td data-bind="text: From">
</td>
<td data-bind="text: To">
</td>
<td data-bind="text: Subject">
</td>
<td data-bind="text: MailDate">
</td>
</tr>
</tbody>
The events are :
ko.utils.arrayForEach(data.mails, function (mail) {
mail.isSelected = ko.observable(false);
mail.isSelected.subscribe(function (myvalue) {
console.log(myvalue);
});
});
self.navigateToMail = function (mail) {
location.hash = mail.Folder() + '/' + mail.Id();
};
I trimmed of unnecessary codes . Just have put where the problem has occurred .
You will essentially need to cancel the event bubbling on click.
Here's an example of how you can do that:
<div data-bind="click: parentClick">
<input type="checkbox" data-bind="checked: isSelected, click: function(){return true}, clickBubble: false">
</div>
See here: http://jsfiddle.net/2M9XP/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With