fix(validate): reset validation result on validators change (#565)
This commit is contained in:
parent
5a0b2c41ea
commit
ce6a89c895
2 changed files with 20 additions and 1 deletions
|
|
@ -200,7 +200,7 @@ export const ValidateMixin = dedupeMixin(
|
|||
if (name === 'validators') {
|
||||
// trigger validation (ideally only for the new or changed validator)
|
||||
this.__setupValidators();
|
||||
this.validate();
|
||||
this.validate({ clearCurrentResult: true });
|
||||
} else if (name === 'modelValue') {
|
||||
this.validate({ clearCurrentResult: true });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -812,6 +812,25 @@ export function runValidateMixinSuite(customConfig) {
|
|||
expect(el.validationStates.error).to.eql({});
|
||||
});
|
||||
|
||||
it('clears current validation results when validators array updated', async () => {
|
||||
const validators = [new Required()];
|
||||
const el = await fixture(html`
|
||||
<${tag}
|
||||
.validators=${validators}
|
||||
>${lightDom}</${tag}>
|
||||
`);
|
||||
expect(el.hasFeedbackFor).to.deep.equal(['error']);
|
||||
expect(el.validationStates.error).to.eql({ Required: true });
|
||||
|
||||
el.validators = [];
|
||||
expect(el.hasFeedbackFor).to.not.deep.equal(['error']);
|
||||
expect(el.validationStates.error).to.eql({});
|
||||
|
||||
el.validators = [new Required()];
|
||||
expect(el.hasFeedbackFor).to.deep.equal(['error']);
|
||||
expect(el.validationStates.error).to.not.eql({});
|
||||
});
|
||||
|
||||
describe('Events', () => {
|
||||
it('fires "showsFeedbackForChanged" event async after feedbackData got synced to feedbackElement', async () => {
|
||||
const spy = sinon.spy();
|
||||
|
|
|
|||
Loading…
Reference in a new issue