diff --git a/packages/validate/src/ValidateMixin.js b/packages/validate/src/ValidateMixin.js index 82c5cb91e..8252ab75f 100644 --- a/packages/validate/src/ValidateMixin.js +++ b/packages/validate/src/ValidateMixin.js @@ -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 }); } diff --git a/packages/validate/test-suites/ValidateMixin.suite.js b/packages/validate/test-suites/ValidateMixin.suite.js index 03f1d95a0..8b965b548 100644 --- a/packages/validate/test-suites/ValidateMixin.suite.js +++ b/packages/validate/test-suites/ValidateMixin.suite.js @@ -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} + `); + 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();