You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an attribute is validated against ds-error this validation is reset when the value of the attribute is changed. However, for a belongsTo relationship this is not true. Consider a situation when the app receives 2 errors from the backend. The user sees that, for example, a string and a dropdown value (which is bound to a relationship) are invalid. He alters the text field and the dropdown selected value, but only the text field becomes valid which is not consistent.
Here is a simple text for the described behaviour:
import{module,test}from'qunit';import{buildValidations,validator}from'ember-cp-validations';importModel,{attr,belongsTo}from'@ember-data/model';import{setupTest}from'ember-qunit';module('Unit | Utility | ds-error issue',function(hooks){setupTest(hooks);test('ds-error',asyncfunction(assert){constvalidations=buildValidations({text: validator('ds-error'),author: validator('ds-error'),});constuserModel=Model.extend({name: attr('string'),});constcommentModel=Model.extend(validations,{text: attr('string'),author: belongsTo('test-user-model'),});this.owner.register('model:test-user-model',userModel);this.owner.register('model:test-comment-model',commentModel);conststore=this.owner.lookup('service:store');constuser=store.createRecord('test-user-model',{id: 1,name: 'Charlie'});constcomment=store.createRecord('test-comment-model',{id: 1,text: 'note',author: user});assert.ok(comment.validations.isValid,'comment is valid');comment.errors.add('text','text error');comment.errors.add('author','author error');assert.notOk(comment.validations.attrs.text.isValid,'comment text is not valid');assert.notOk(comment.validations.attrs.author.isValid,'comment author is not valid');comment.set('text','new text');assert.ok(comment.validations.attrs.text.isValid,'comment text is valid');comment.set('author',store.createRecord('test-user-model',{id: 2,name: 'Bob'}));// the below assertion is not satisfiedassert.ok(comment.validations.attrs.author.isValid,'comment author valid');});});
So please tell me wether this is not a bug and how to reset the state of the validation to make the model valid.
The text was updated successfully, but these errors were encountered:
Environment
ember-cli: 3.12
ember: 3.12
ember-cp-validations: 4.0.0-beta.9
Steps to Reproduce
When an attribute is validated against
ds-error
this validation is reset when the value of the attribute is changed. However, for abelongsTo
relationship this is not true. Consider a situation when the app receives 2 errors from the backend. The user sees that, for example, a string and a dropdown value (which is bound to a relationship) are invalid. He alters the text field and the dropdown selected value, but only the text field becomes valid which is not consistent.Here is a simple text for the described behaviour:
So please tell me wether this is not a bug and how to reset the state of the validation to make the model valid.
The text was updated successfully, but these errors were encountered: