Hello,
I had issues that the KO.js checked binding doesnt work for checkboxes in a Bootstrap 3 btn-group.
The Bootstrap 3 checkboxes inside a btn-group are toggled on/off via their DOM property checked.
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default">
<input type="checkbox" data-bind="checkedProp: observable1" />
Observable 1
</label>
<label class="btn btn-default">
<input type="checkbox" data-bind="checkedProp: observable2" />
Observable 2
</label>
</div>
This custom binding supports the Bootstrap 3 btn-group checkboxes:
ko.bindingHandlers.checkedProp = {
init: function(element, valueAccessor) {
Object.defineProperty(element, 'checked', {
set: function(newValue) {
var value = valueAccessor();
value(newValue);
}
});
},
update: function(element, valueAccessor) {
var value = ko.unwrap(valueAccessor());
element.checked = value;
}
};
I hope this can help anyone who has the same binding issues.