6

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

Error: client side validation errors encountered - see the entity Errors collection on this object for more detail.

I believe it's somewhere in entity.entityAspect.getValidationErrors() but am having trouble figuring out how to get the actual error out of it.

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

user1813251
  • 329
  • 3
  • 18

2 Answers2

9

See :

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

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

Simple example:

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

To get all of the errors in an EntityManager you can use

manager.getEntities().forEach(function(entity) { 
   var errors = entity.entityAspect.getValidationErrors();
   //.. do something with the errors ..
});
Colin
  • 22,328
  • 17
  • 103
  • 197
Jay Traband
  • 17,053
  • 1
  • 23
  • 44
  • I have looked into that before. getValidationErrors always comes back as Cannot call method 'getValidationErrors' of undefined :manager = configureBreezeManager();manager.entityAspect.getValidationErrors() – user1813251 Jan 21 '14 at 19:33
  • 1
    Please look at the validation examples in the DocCode sample in the Breeze zip. But just looking at your comment, an EntityManager does not have an 'entityAspect' property, the entities themselves each have an 'entityAspect' property. So if you want all of the errors in an entityManager use manager.getEntities().forEach(function(ent) { var errors = ent.entityAspect.getValidationErrors()); – Jay Traband Jan 21 '14 at 21:22
0

You can 'catch' the errors when you try and save, like so:

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

Just keep in mind that any code after that will need to be in a

setTimeout(function() {}, 0);

as the catch is async. This was you don't need to loop through all the entities in the app to find the ones with errors.

Jim Doyle
  • 2,302
  • 1
  • 16
  • 12