From e24f2efcff7ffba6076faa4f3ce17ca4c8062b72 Mon Sep 17 00:00:00 2001 From: Hzunax Date: Thu, 28 May 2020 22:03:15 +0200 Subject: [PATCH] fix(field): remove validation toggled disable when disable is toggled to true, validation should be removed --- .../form-core/src/validate/ValidateMixin.js | 2 +- packages/form-core/test/lion-field.test.js | 31 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/packages/form-core/src/validate/ValidateMixin.js b/packages/form-core/src/validate/ValidateMixin.js index abae720dc..56bd0516a 100644 --- a/packages/form-core/src/validate/ValidateMixin.js +++ b/packages/form-core/src/validate/ValidateMixin.js @@ -265,7 +265,7 @@ export const ValidateMixin = dedupeMixin( async validate({ clearCurrentResult } = {}) { if (this.disabled) { this.__clearValidationResults(); - this.__validationResult = []; + this.__finishValidation({ source: 'sync', hasAsync: true }); this._updateFeedbackComponent(); return; } diff --git a/packages/form-core/test/lion-field.test.js b/packages/form-core/test/lion-field.test.js index 4a37f1889..7a87784a7 100644 --- a/packages/form-core/test/lion-field.test.js +++ b/packages/form-core/test/lion-field.test.js @@ -380,7 +380,36 @@ describe('', () => { expect(el.validationStates.error).to.have.a.property('HasX'); expect(disabledEl.hasFeedbackFor).to.deep.equal([]); - expect(disabledEl.validationStates.error).to.equal(undefined); + expect(disabledEl.validationStates.error).to.deep.equal({}); + }); + + it('should remove validation when disabled state toggles', async () => { + const HasX = class extends Validator { + constructor() { + super(); + this.name = 'HasX'; + } + + execute(value) { + const result = value.indexOf('x') === -1; + return result; + } + }; + const el = await fixture(html` + <${tag} + .validators=${[new HasX()]} + .modelValue=${'a@b.nl'} + > + ${inputSlot} + + `); + expect(el.hasFeedbackFor).to.deep.equal(['error']); + expect(el.validationStates.error).to.have.a.property('HasX'); + + el.disabled = true; + await el.updateComplete; + expect(el.hasFeedbackFor).to.deep.equal([]); + expect(el.validationStates.error).to.deep.equal({}); }); it('can be required', async () => {