knockout.js - Knockout checked and click both (prevent double checkbox switch) -


i have checkbox described this:

<input id="checkbox1" type="checkbox" data-bind="     click: function () { handle_compare($element) },     checked: is_product_compared"> 

.handle_compare() inverts observable "is_product_compared", problem allow normal behavior checkbox, if click on it, seems double switches, , never see changes.

if bind handle_compare button - ok, checkbox switches normally. there way allow both bindings?

you can see demo here, button ok, checkbox has wrong behavior.

http://jsfiddle.net/g5rpcw2c/1/

you need inline click handler return true:

http://jsfiddle.net/g5rpcw2c/2/

either:

<input id="checkbox1" type="checkbox" data-bind="     click: function () { handle_compare($element); return true; },     checked: is_product_compared"> 

or (since handle_compare returns true):

<input id="checkbox1" type="checkbox" data-bind="     click: function () { return handle_compare($element) },     checked: is_product_compared"> 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -