Reputation: 896
I'm pplaying with the editing place like described in the http://emberjs.com/guides/getting-started/toggle-todo-editing-state/
And the solution I came up with is to save the value of the model before the editing and than, after editing is finished, decide to restore it whether cancel was pressed or not.
Here is the jsbin http://emberjs.jsbin.com/hesib/1/edit and I'm afraid it is not so good and idiomatic.
What do you say?
Upvotes: 0
Views: 360
Reputation: 6338
I am not quite sure what you are trying to achieve.
If you like to restore whole model at once to last committed state you should go with this.rollback(). But be aware that this.rollback is restoring to last committed state via this.save(), regardless if save false or not. For details on expected behavior of this.rollback: http://discuss.emberjs.com/t/expected-behaviour-of-rollback-after-save-attempt-returns-422-ember-data-1-0/2513
If you like a feature to restore just one attribute I would recommend not to change the original model but to go with a view: Create a temporary object which stores values of model, implementing there editing and restore features for this temporary model and if changes should be saved push updated values to controller, update model there and save it.
If you like to save a model and continue editing, you could just use save but keep your view in editing mode.
Upvotes: 1