Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model rollback doesn't clear model.errors.attribute #3498

Closed
smcclstocks opened this issue Jul 6, 2015 · 4 comments
Closed

model rollback doesn't clear model.errors.attribute #3498

smcclstocks opened this issue Jul 6, 2015 · 4 comments

Comments

@smcclstocks
Copy link

Steps to reproduce:

  1. dirty model
  2. save model
  3. get validation errors populating model.errors
  4. model.rollbackAttributes()
  5. model.errors.attribute.length != 0 but model.errors.length == 0

This leave the UI displaying errors when the model has been rolled back & the validation errors should no longer be present. In my case the attribute is name firstName so in step 5 above model.errors.attribute.length is model.errors.firstName.length. I could be missing something so sorry for the waste of time if so.. i can't seem to work around this although model.get('errors').has('firstName') does return false after the rollback even though the array of messages are still present.

When I transition away & come back the UI no longer shows the errors so I wasn't sure if this was something to do with my templates instead. Thanks ahead of time.

@smcclstocks
Copy link
Author

DEBUG: -------------------------------
ember.debug.js:5361DEBUG: Ember : 1.13.2
ember.debug.js:5361DEBUG: Ember Data : 1.13.4
ember.debug.js:5361DEBUG: jQuery : 1.11.3
ember.debug.js:5361DEBUG: Ember Simple Auth : 0.8.0
ember.debug.js:5361DEBUG: Ember Simple Auth Cookie Store : 0.8.0
ember.debug.js:5361DEBUG: Ember Simple Auth OAuth 2.0 : 0.8.0
ember.debug.js:5361DEBUG: -------------------------------

@tchak
Copy link
Member

tchak commented Jul 6, 2015

looking in to it

@tchak
Copy link
Member

tchak commented Jul 17, 2015

@smcclstocks what is the exact value of model.get('errors.attribute.length') in your case? I have run some tests and I am getting null which is expected. Using != 0 in such cases is usually a bad idea. You should use Ember.isEmpty(model.get('errors.attribute')).

@smcclstocks
Copy link
Author

I was only using != 0 for illustration & don't use that in my app at all. But I notice the same thing you said with is model.get('errors.attribute.length') is null after the rollbackAttributes(). But the templates don't reflect that for some reason. The template will properly reflect the rollback by setting the value back to the original but the template never reflects the fact that the attributes error length is no null. Here's my example:

              <p>{{model.errors.street}}</p>
              <p>{{model.errors.street.length}}</p>
              {{#each model.errors.street as |err|}}
                <p>{{err.message}}</p>
              {{/each}}

In that case the attribute I'm testing with is obviously named street & after the rollback I get what you said in the console logs:

    console.log @get('controller.model.errors.length')
    console.log @get('controller.model.errors.street.length')

    0
    null

But the template instead continues to show:

              <p>[object Object]</p>
              <p>1</p>
              <p>>150 characters & required</p>

Do you see that in your testing as well?

tchak added a commit to tchak/data that referenced this issue Jul 18, 2015
tchak added a commit to tchak/data that referenced this issue Jul 18, 2015
tchak added a commit to tchak/data that referenced this issue Jul 18, 2015
@bmac bmac closed this as completed in ec5d73e Jul 20, 2015
bmac pushed a commit to bmac/data that referenced this issue Jul 21, 2015
Closes emberjs#3498

(cherry picked from commit ec5d73e)

Conflicts:
	packages/ember-data/lib/system/model/errors.js
bmac pushed a commit that referenced this issue Jul 22, 2015
Closes #3498

(cherry picked from commit ec5d73e)

Conflicts:
	packages/ember-data/lib/system/model/errors.js
jcope2013 pushed a commit to jcope2013/data that referenced this issue Aug 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants