I’m trying to see if I can find a knockout equivalent for this bit of jQuery:
http://jsfiddle.net/chriscoyier/BPhZe/76/
This is what I have to far, but all the items are bound to the same observable so it obviously doesn’t work.
html:
<form>
<div>
<input type="checkbox" name="option-1" id="option-1" data-bind="checked: buttonEnabled"> <label for="option-1">Option 1</label>
</div>
<div>
<input type="checkbox" name="option-2" id="option-2" data-bind="checked: buttonEnabled"> <label for="option-2">Option 2</label>
</div>
<div>
<input type="checkbox" name="option-3" id="option-3" data-bind="checked: buttonEnabled"> <label for="option-3">Option 3</label>
</div>
<div>
<input type="checkbox" name="option-4" id="option-4" data-bind="checked: buttonEnabled"> <label for="option-4">Option 4</label>
</div>
<div>
<input type="checkbox" name="option-5" id="option-5" data-bind="checked: buttonEnabled"> <label for="option-5">Option 5</label>
</div>
<div>
<input type="button" value="Do thing" data-bind="enable: buttonEnabled">
</div>
</form>
javascript:
var viewModel = {
buttonEnabled: ko.observable(true)
};
ko.applyBindings(viewModel);
Yes. See the updated jsFiddle here: http://jsfiddle.net/WdWEW/4/
I did a few things.
valueattribute to each of the checkboxesoptionswhich is an observableArraybuttonEnabledto a computed property that returnstrueif theoptionsproperty has a length greater than zero.Here’s the updated view model.
Here’s the updated view: