With a clean knockout, you can do this by basically switching the observable isDisabled, which updates the attribute of the disabledrelated item. You can use knockout binding attrto set attributes on elements.
var ViewModel = function() {
var self = this;
self.isDisabled = ko.observable(false);
this.disable = function(){
self.isDisabled(true);
}
this.enable = function(){
self.isDisabled(false);
}
};
ko.applyBindings(new ViewModel());
<div>
<input type="text" data-bind="attr : {'disabled' : isDisabled}"/>
<input type="text" data-bind="attr : {'disabled' : isDisabled}"/>
<button data-bind="click : disable">Disable</button>
<button data-bind="click : enable">Enable</button>
</div>
https://jsfiddle.net/xggu9Lv2/2/
source
share