1

I'm trying to save a form on submit but discard changes in any other case. The problem is that even after a commit the isDirty flag is true.

App.UserController = Ember.Controller.extend({
    enterEditing: function() {
    this.transaction = App.store.transaction();
    this.transaction.add(this.get('content'));
  },
  updateEditing: function() {
    console.log('update saved');
    this.transaction.commit();
    this.transaction = null;
  }
});
App.UserView = Ember.View.extend({ 
    templateName: 'edit-user',
    willDestroyElement: function() {
    console.log(this.getPath('controller.content.isDirty'));
    if (this.getPath('controller.content.isDirty')) {
      console.log('unsaved changes');
      this.getPath('controller.content.transaction').rollback();   
    }     
  }
});

And my router section:

showNew: Ember.Route.extend({
   route: '/user/new',
          cancelEditUser: Ember.Route.transitionTo('index'),
          connectOutlets: function(router) {
            router.get('applicationController').connectOutlet('user');
            router.get('userController').enterEditing();
          }
        }),


  update: function(router, event) {
    router.get('userController').updateEditing();
    router.transitionTo('index');
  }
3
  • It should actually keep both isDirty and isSaving as true until your service returns a 200. After that, both flags should be automatically set to false. Check the isSaving flag, maybe your service hasn't finished saving it at the time you checked the isDirty Dec 19, 2012 at 16:32
  • isSaving goes from false to true but isDirty stays true. I'm returning a 200 with a node.js/express backend - res.jsonp(200) Dec 19, 2012 at 18:55
  • I'm also seeing this with FixtureAdapter on rc1
    – KOGI
    Mar 29, 2013 at 22:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.