Created
April 25, 2012 15:01
-
-
Save fjeldstad/2490390 to your computer and use it in GitHub Desktop.
Extension method for Knockout that enables an Errors collection on observables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (ko, undefined) { | |
ko.observable.fn.withValidation = function () { | |
var observable = this; | |
observable.Errors = ko.observableArray(); | |
observable.HasErrors = ko.computed(function () { | |
return observable.Errors().length > 0; | |
}); | |
return observable; | |
}; | |
} (ko)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment