Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handleDS.errors? #118

Closed
thiyagu06 opened this issue Feb 12, 2016 · 5 comments
Closed

How to handleDS.errors? #118

thiyagu06 opened this issue Feb 12, 2016 · 5 comments

Comments

@thiyagu06
Copy link

Is there any code need be wriiten if server throws 422 errors.The one which is mentioned in the below link.

http://emberjs.com/api/data/classes/DS.Errors.html

@thiyagu06 thiyagu06 changed the title How to handle handling DS.errors? How to handleDS.errors? Feb 12, 2016
@offirgolan
Copy link
Collaborator

You can do something like this

const Validations = buildValidations({
  foo: validator(function(value, options, model, attribute) {
    if (model.get('errors').has(attribute)) {
      return model.get(`errors.${attribute}.messages.firstObject`);
    }
    return true;
  }, { dependentKeys: ['errors.foo.messages.[]']})
});

@thiyagu06
Copy link
Author

it is not working for embedded belongs to and has many relationships..

@offirgolan
Copy link
Collaborator

You have to put your validations on the model that has the errors. You cant validate child on model.child if that makes sense...

On a side note: @blimmer is this the sort of issue you have been facing as well? Would it help to have a validator('ds-error') that handles the dependentKeys and spits out the last error for the given attribute?

@blimmer
Copy link
Collaborator

blimmer commented Feb 20, 2016

@offirgolan that would be helpful - it would be especially helpful if it could identify the model property and mark that invalid (e.g. on a user form, highlight what is invalid like birthdate).

@offirgolan
Copy link
Collaborator

@thiyagu06 v2.5.0 has been released with a new DS Error validator 😸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants