jbartolome
jbartolome

Reputation: 302

Knockout.js event click - error with checkboxes

I have something like this:

<div class="dialog" data-bind="event: {click: clickEvent}">
 ...

    <div class="myClass">
      <label><input type="checkbox" name="cbname" class="checkbox" data-bind="checked: checkedFunction" /></label>
    </div>

       ...

</div>

Because of the event click, my checkbox is always checked and there is no way to uncheck it. If I remove the event click on the parent div, everything works good.

Do you have any idea why it's not working?

Thanks

Upvotes: 0

Views: 174

Answers (1)

Anders
Anders

Reputation: 17564

Your click handler must return true, otherwise it will cancel bubble of click event

http://jsfiddle.net/Dn3jr/

foo: function() {
    this.fooCount(this.fooCount() + 1);

    return true;
}

edit: As a side note I think its very wrong that the viewmodel needs to be wary of this. Bubbling of click events is a View only notion, and because of that it should not need to be handled by the VM

Upvotes: 2

Related Questions