Skip to content

Instantly share code, notes, and snippets.

@fjeldstad
Created April 25, 2012 15:01
Show Gist options
  • Save fjeldstad/2490390 to your computer and use it in GitHub Desktop.
Save fjeldstad/2490390 to your computer and use it in GitHub Desktop.
Extension method for Knockout that enables an Errors collection on observables
(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