Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

knockout.js and listen to check event on checkbox

I'm trying to get a function to execute when a checkbox is checked or unchecked to verify all checkboxes are unchecked but it never gets executed. I assume I'm not doing it correctly.

@Html.CheckBox("Subscription", new{ data_bind="disable: Disabled, checked: Checked, click: $parent.allSubscriptionsUnchecked"} )  
like image 658
Mike Flynn Avatar asked May 23 '12 23:05

Mike Flynn


1 Answers

You can add both a checked and click binding to an input. However, you would want to return true; from the click handler. This will allow the default action to proceed (the checkbox will be checked/unchecked).

Here is a sample: http://jsfiddle.net/rniemeyer/cnkVA/

An alternative technique is to push this logic into your view model and subscribe to changes to a boolean observable and execute your action like: http://jsfiddle.net/rniemeyer/cnkVA/2/

like image 126
RP Niemeyer Avatar answered Sep 21 '22 06:09

RP Niemeyer