Skip to content

Instantly share code, notes, and snippets.

@skinofstars
Last active August 29, 2015 14:07
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 skinofstars/f7e7dd58460eb11316c7 to your computer and use it in GitHub Desktop.
Save skinofstars/f7e7dd58460eb11316c7 to your computer and use it in GitHub Desktop.
ember data not populating model errors
// using ActiveModelAdapter
App.ApplicationAdapter = DS.ActiveModelAdapter.extend();
// simple model
App.Job = DS.Model.extend({
external_ref: DS.attr("string")
});
// creating a new Job.
App.JobsNewController = Ember.Controller.extend({
actions: {
save: function() {
var newJob = this.store.createRecord('job', {
'external_ref' : this.external_ref,
});
newJob.save().then(function(){
}, function(fail){
// server fails validation, so responds to save with {"errors":{"external_ref":["can't be blank"]}}
// InvalidError object
console.log(fail)
// this is the obj sent from server
console.log(fail.errors)
// an ember array of length 0
console.log(newJob.get('errors').toArray())
});
}
}
});
{{!-- jobs/new.hbs --}}
{{#if errors.length}}
There has been an error
{{/if}}
{{input type="text" value=external_ref placeholder='External ref' class="form-control" }}
<button {{action 'save'}}>Save</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment