According to Ember Guides, validation errors will be available on the errors property of the model. But I can't get this to work. Say I have "name" and "displayName" property for a person model. What would the payload be if say I have one error which is "name is empty"?
{"errors":[{"title":"name is empty"}, {"title":"other error"}]}
This format is required by jsonapi so I don't know HOW I can end up with what Ember Guides shows below.
If the backend server returns validation errors after trying to save, they will be available on the errors property of your model. Here's how you might display the errors from saving a blog post in your template:
{{#each post.errors.title as |error|}}
<div class="error">{{error.message}}</div>
{{/each}}
{{#each post.errors.body as |error|}}
<div class="error">{{error.message}}</div>
{{/each}}
Aucun commentaire:
Enregistrer un commentaire