Knockout.js and listen to check check on on checkbox

I am trying to execute a function when a checkbox is checked or unchecked to verify that all checkboxes are unchecked, but it never starts. I guess I'm doing it wrong.

@Html.CheckBox("Subscription", new{ data_bind="disable: Disabled, checked: Checked, click: $parent.allSubscriptionsUnchecked"} ) 
+42
checkbox
May 23 '12 at 23:04
source share
1 answer

You can add the checked and click binding to the input. However, you want return true; from the click handler. This will allow you to continue the action by default (the checkbox will be checked / not checked).

Here is an example: http://jsfiddle.net/rniemeyer/cnkVA/

An alternative method is to push this logic to your view model and subscribe to the changes in the boolean observable and perform your action, for example: http://jsfiddle.net/rniemeyer/cnkVA/2/

+125
May 24 '12 at 1:13
source share



All Articles