Skip to content

Commit

Permalink
Merge pull request #3898 from knownasilya/patch-3
Browse files Browse the repository at this point in the history
Fix DS.Errors summary and error object example
  • Loading branch information
bmac committed Oct 31, 2015
2 parents 31bf071 + 63bbe5e commit f62959a
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions packages/ember-data/lib/system/model/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ var MapWithDefault = Ember.MapWithDefault;
Every DS.Model has an `errors` property that is an instance of
`DS.Errors`. This can be used to display validation error
messages returned from the server when a `record.save()` rejects.
This works automatically with `DS.ActiveModelAdapter`, but you
can implement [ajaxError](/api/data/classes/DS.RESTAdapter.html#method_ajaxError)
in other adapters as well.
For Example, if you had an `User` model that looked like this:
Expand All @@ -44,13 +41,24 @@ var MapWithDefault = Ember.MapWithDefault;
```javascript
{
"errors": {
"username": ["This username is already taken!"],
"email": ["Doesn't look like a valid email."]
}
"errors": [
{
"detail": "This username is already taken!",
"source": {
"pointer": "data/attributes/username"
}
}, {
"detail": "Doesn't look like a valid email.",
"source": {
"pointer": "data/attributes/email"
}
}
]
}
```
For additional information on the error object, see the [JSON API spec](http://jsonapi.org/format/#error-objects).
Errors can be displayed to the user by accessing their property name
to get an array of all the error objects for that property. Each
error object is a JavaScript object with two keys:
Expand Down

0 comments on commit f62959a

Please sign in to comment.