Attempted to handle event `becameInvalid` while in state ‘root.loaded.saved’

Total
1
Shares

I’ve implemented DS.Errors for my RestAdapter, thanks to Alex Spellers tutorial on server side validation.

However, in this part of my app I want to do a simple client side check to see if the form is complete. (Why not have DS.Errors handle all the errors?)

  process: function(upload) {
    var form = upload.get('form');

    if (!isComplete(form)) {
        upload.get('errors').add('field', 'field isempty'); 
        return;
    }
    // else "Processing..."

The logic here is somewhat simplified, but errors.add() should invalidate, and add an error to the model. However I’m getting the following error:

Uncaught Error: Attempted to handle event `becameInvalid` on <@model:upload:54a1f298ef912a2ace760b0f> while in state root.loaded.saved. 

I have read about the state manager, but am unsure as to how, and what state I should transition to before adding an error to my model.

Thanks in advance!

Ember      : 1.8.1
Ember Data : 1.0.0-beta.11
Handlebars : 1.3.0
jQuery     : 1.11.2

Solution

After revisiting this I came across the following post. What solved my problem was not sending willCommit, but sending upload.send('becomeDirty'); before executing the following:

upload.get('errors').add('field', 'field isempty'); 

Now errors can be added as the upload model is not in the saved state.

Leave a Reply

Your email address will not be published. Required fields are marked *