how to view breeze client validation errors
Asked Answered
A

2

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.

Autograft answered 20/1, 2014 at 14:54 Comment(0)
P
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 ..
});
Pantry answered 21/1, 2014 at 6:2 Comment(2)
I have looked into that before. getValidationErrors always comes back as Cannot call method 'getValidationErrors' of undefined :manager = configureBreezeManager();manager.entityAspect.getValidationErrors()Autograft
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());Pantry
K
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.

Kilpatrick answered 16/10, 2016 at 13:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.