ericmbarnard/Knockout-Validation — Issue #33: Adding minCount, maxCount validation to observableArrays
Author: grofit
Created: 2012-03-02 14:04:33+00:00
State: open

Would it be possible to add validation rules for observableArrays, so you could say that an observable array should have a minCount or maxCount? i.e:

```
function SomeViewModel() {
var self = this;
self.Addresses = ko.observableArray().extend({minCount: 1, maxCount: 3});
self.ViewModelErrors = ko.validation.group(self);

self.SubmitViewmodel = function() {
if(ViewModelErrors().length > 0) {
alert("Please ensure you only have at least 1 address and no more than 3");
return;
}
// Do some submission stuffs
};
}
```

I have a scenario where I would ideally like the limit the amount of elements they can create within ``observableArray``, currently I just check on the size every time they alter the array and deal with it manually, but it would be nice if I could farm some of that logic off to the validation library.