I have ko.observableArrays with validation on the items. The user can mark a item as deleted. When it is marked as deleted, I need to disable validation on that item.
How do you dynamically disable validation?
Example: http://jsfiddle.net/3RZjT/2/
<div data-bind="foreach: names">
<input data-bind="value: name, valueUpdate: 'afterkeydown'" /> <a data-bind="click: deleteMe, text:deleted()?'undelete':'delete'" href="#">delete</a><br/>
</div>
function Person(name){
var self = this;
self.name = ko.observable(name).extend({ required: true});
self.deleted = ko.observable(false);
self.deleteMe = function(){
self.deleted(!self.deleted());
self.deleted.extend({ validatable: !self.deleted()});
};
}
var viewModel = {
names: ko.observableArray([new Person("Ken"), new Person("")])
};
ko.applyBindings(viewModel);
self.name.extend({ validatable: !self.deleted()});
in yourdeleteMe
function. – Laise