Reputation: 471
I am building an ember.js web app with user registration. If the registration fails (e.g invalid email) the API returns an error. The problem is this puts the model into an error state and if the user trys to make another attempt at registering, Ember.js raiser an error Uncaught Error: Attempted to handle event 'willSetProperty' on <App.User:ember451:null> while in state rootState.error.
and then seems to become unresponsive.
Do I have to manually reset the state after the error?
becameInvalid: function() {
// reset the state after an error
var parentState = this.get('stateManager').get('currentState').parentState.dirtyType;
if (parentState === "updated") {
this.get('stateManager').transitionTo('loaded.updated');
} else {
this.get('stateManager').transitionTo('loaded.created.uncommitted');
}
}
This seems kind of strange. Have I set this up incorrectly? Is there another way or should I reset after errors?
Upvotes: 1
Views: 444
Reputation: 19050
Do I have to manually reset the state after the error?
Yes.
This seems kind of strange.
Agreed. For sure it will be improved in future versions of ember-data.
Have I set this up incorrectly?
Nope, you did it right
Is there another way or should I reset after errors?
No other way AFAIK.
See this post: Ember: transaction.commit does not fire after becameInvalid event
Upvotes: 1
Reputation: 47367
You'd have to manually reset the state. Ember itself doesn't deal with model management. Ember-Data and Ember-Model (which are separate from Ember), have the ability to rollback/revert "dirty" models.
Upvotes: 0