Created
May 8, 2014 01:49
-
-
Save amiel/8ba91a0bf689f0a7ded9 to your computer and use it in GitHub Desktop.
ember-validators with server validation errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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