Skip to content

Instantly share code, notes, and snippets.

@amiel
Created May 8, 2014 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amiel/8ba91a0bf689f0a7ded9 to your computer and use it in GitHub Desktop.
Save amiel/8ba91a0bf689f0a7ded9 to your computer and use it in GitHub Desktop.
ember-validators with server validation errors
MyController = Ember.Controller.extend({
actions: {
save: function() {
this.get('model').save().then(function() {
// Success, maybe transitionToRoute or whatever
}, function(xhr) {
// Oh noes, we had an error, maybe it's a validation error
if (xhr.status == 400) {
$.parseJSON(xhr.responseText).each(function(attribute, errors) {
this.get('errors').set(attribute, errors);
});
}
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment