@hashbug wrote:
While trying to handle server side errors in Ember application, I am unable to show the errors in templates. On record.save action the API returns errors as:
{ "errors":[ { "detail":"can't be blank", "source":{ "pointer": "/data/attributes/username" } } ] }
In template file, the code for showing errors for username attribute is:
{{input type="text" value=username }} {{#each model.errors.username as |error|}} {{error.message}} {{/each}} {{input type="text" value=email }} ` <button {{action 'register'}}>Register</button>`
the action "register" tries saving the user as:
register: function(){ var username = this.controller.get('username'); var email = this.controller.get('email'); var user = this.store.createRecord('user',{ email: email, username: username }); user.save().then(function(){ //handle success },function(error){ console.log(user.get('errors.username')); }); });
In console I got the array[object] for errors.username where object contains the desired attribute and message, But in template I am not able to access these messages.
I have posted this question on stackoverflow as well. http://stackoverflow.com/questions/40081844/server-side-errors-not-populated-in-ember-model-with-restadapter
Posts: 1
Participants: 1