knockout-validator is an extensible model validation system for knockout framework, that besides normal validations it handles well nested validations and array validations. Validation is performed on the view model. The UI can selectively register to display
Working with knockout (http://knockoutjs.com/) system is extremely useful for any ajax enabled rich application. We create complex view models which are projected through knockout
system to the user interface.
One thing the developer will soon or later will have to handle is validation. For this there are various approaches such as:
- Manually, by using observable extensions according to knockout documentation (http://knockoutjs.com/documentation/extenders.html)
- Manually, by using computed observables according to knockout documentation (http://knockoutjs.com/documentation/computedObservables.html)
- Using a third party validation system, like jquery validation plugin (http://docs.jquery.com/Plugins/Validation)
- And last but not least, using the excellent knockout-validation (https://github.com/ericmbarnard/Knockout-Validation) by Eric
Barnard which, according to my opinion, would be the best approach.
The need for knockout-validator was raised because I needed a validation system that
- could handle well array validations and array items validations
- could watch and resubscribe to observables even if they are nested
- could provide hierarchical validation, in that in a complex view model, with
many levels of nesting for example Person=> Contacts=> Contact=> Addresses=>Address=>PostalCode I could subscribe for changes only to the Addresses item, or to the full Person view model etc with the
minimum of coding (no need to create computed observables to forward validation results to parent objects etc)
- would give me with zero-coding the opportunity to track changes to my objects ( so that i could get events/subscribe not only to "isValid" observable but also to
hasValidChanges observable, which will be raised only if i have
- separate well UI vs Model and perform clean View Mode validation which will be projected -and not merged- with the UI
- create validations of ko.computed (or ko.dependentObservable) objects
- display validation result to whichever ui element ( eg. you can have an input element, bind its value to some object but map its validation result from the validation of a computed element and not the input's value)
- create custom function validations
Documentation and samples will be added soon.
For starters you can download the initial release from "Downloads" section.
You can follow me on twitter: