jeudi 15 juin 2017

ember.js manually set hasDirtyAttributes not cleared when saving

I have a save button in my template that activates when the model hasDirtyAttributes

The hasDirtyAttributes flag doesn't seem to be set when a reference to a related model changes.

Example
I have a drop-down that allows picking of a related model called contact
If I change any direct attributes (e.g. name), everything works as expected, and the save button activates.
When I change the contact, it doesn't, I assume this is by design, So I set the flag when my change action is fired.

I am setting this in my route action like so:

actions:{ 

    updateProductionContact: function(contact){
         this.set('currentModel.customer.hasDirtyAttributes',true);             
         this.set('currentModel.customer.production_contact',contact);
    },
}

Now it works again. When I change a contact, the save button lights up.
However, when I now click save, the hasDirtyAttributes flag stays true (button remains active), whereas previously it was cleared until another change was made.

I would expect the framework to re-set the flag automatically after a successful save, just as before. I could of course re-set the flag on the save action of the button.

It feels like I am hacking my way around a problem, and that perhaps hasDirtyAttributes shouldn't be set manually or that I should be using a different indicator of dirtiness.




Aucun commentaire:

Enregistrer un commentaire