How to View Breeze Client Validation Errors

I read the breeze validator information but am not sure how to view the actual error that is occurring.

Error: client-side validation errors were detected - for more information, see the Errors collection of errors on this object.

I believe this is somewhere in entity.entityAspect.getValidationErrors (), but it's hard for me to figure out how to get the actual error from it.

I am trying to insert a record into an entity and save changes when this error message occurs.

+6
source share
2 answers

See:

http://www.breezejs.com/sites/all/apidocs/classes/ValidationError.html

http://www.breezejs.com/sites/all/apidocs/classes/EntityAspect.html#method_getValidationErrors

A simple example:

var errors = entity.entityAspect.getValidationErrors(); errors.forEach(function(ve) { var errorMessage = ve.errorMessage; var property = ve.property; }); 

To get all errors in EntityManager, you can use

 manager.getEntities().forEach(function(entity) { var errors = entity.entityAspect.getValidationErrors(); //.. do something with the errors .. }); 
+9
source

You can catch errors when trying to save, for example:

 manager.saveChanges() .catch(function(error){ console.log("error catch", error, error.entityErrors); }); 

Just keep in mind that any code after that should be in

 setTimeout(function() {}, 0); 

since catch is asynchronous. You didn’t need to iterate over all the entities in the application to find those who have errors.

0
source

All Articles