Based on Breeze documentation I have the following solution to add any client side validation errors to a property (fieldsWithErrors) on my entity. This works well and I can grab the relevant error to a particular property and apply css classes to indicate validation errors to the user. episodeManager is my EntityManager and Reminder is my entity.
episodeManager.metadataStore.registerEntityTypeCtor("Reminder", sr.Reminder, function (entity) {
entity.fieldsWithErrors = ko.observableArray([]);
entity.entityAspect.validationErrorsChanged.subscribe(function () {
entity.fieldsWithErrors.removeAll();
var errors = entity.entityAspect.getValidationErrors();
$.each(errors, function () {
entity.fieldsWithErrors.push(this.propertyName);
});
});
});
I've added some server side validation in the form of custom .Net attributes (the client side validation errors above are Breeze cloning [Required] attributes into rules, I have no custom Breeze validation rules). Any violation of these server-side rules are returned to Breeze in the fail() promise after saveChanges(). I can't think of a clean way to combine these into my fieldsWithErrors entity property alongside any client side errors as if they were all the same. Is there a much simpler way to do this?