Is there any way to specify an enable condition for the click binding? For example if I have the following:
Clic
You can use this approach that I did for anchors
http://jsfiddle.net/xCfQC/11/
(function() {
//First make KO able to disable clicks on Anchors
var orgClickInit = ko.bindingHandlers.click.init;
ko.bindingHandlers.click.init = function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
if(element.tagName === "DIV" && allBindingsAccessor().enable != null) {
var disabled = ko.computed({
read: function() {
return ko.utils.unwrapObservable(allBindingsAccessor().enable) === false;
},
disposeWhenNodeIsRemoved: element
});
ko.applyBindingsToNode(element, { css: { disabled: disabled} });
var handler = valueAccessor();
valueAccessor = function() {
return function() {
if(ko.utils.unwrapObservable(allBindingsAccessor().enable)) {
handler.apply(this, arguments);
}
}
};
}
orgClickInit.apply(this, arguments);
};
})();
More details: https://github.com/AndersMalmgren/Knockout.BindingConventions/wiki/Button-convention