0

Errors on attributes located within related models is now my problem. I can see the errors on these related models by doing model.errors.content or model.errors.messages but if I want to check a particular attribute on a related model in order to highlight field errors I get null or undefined values.

See below screen shot for more info

Invaild Error object: enter image description here

Model After error: In this object i am getting the attribute and message but i use model.get("errors.phone"

enter image description here

6
  • can you show what response your backend is giving, when validations fail? I suspect your error json is in wrong format Commented Jan 14, 2016 at 14:34
  • Did you include your validations mixin? Commented Jan 14, 2016 at 15:06
  • please specify your ember and ember-data versions. Commented Jan 14, 2016 at 20:06
  • {"errors":{"phone":["is invalid"]}} Yes i have included validation mixin Ember : 1.13.13 Ember-data : 2.2.1 Commented Jan 15, 2016 at 12:42
  • Did you ever find the reason for this? I am finding myself in somewhat the same boat. My errors are not being populated as I expect. I am using the correct JSON API format expected. Commented Oct 5, 2016 at 18:08

1 Answer 1

0

My best guess is, you need to update your error serializer to send data in a format expected by Ember Data JSON Adapter.

It's best explained in detail in this stackoverflow answer, but as a gist you should format your data in a following way:

{
  "errors": 
  [
    {
      "detail": "is invalid",
      "source": {
        "pointer": "data/attributes/phone"
      }
    }
  ]
}  

The pointer must correspond to your model attribute, so phone in this example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.