Merge pull request #738 from Hzunax/fix/toggle-disabled-validation

fix(field): remove validation toggled disable
This commit is contained in:
Joren Broekema 2020-06-02 08:58:28 +02:00 committed by GitHub
commit 5f55c1d3c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View file

@ -265,7 +265,7 @@ export const ValidateMixin = dedupeMixin(
async validate({ clearCurrentResult } = {}) { async validate({ clearCurrentResult } = {}) {
if (this.disabled) { if (this.disabled) {
this.__clearValidationResults(); this.__clearValidationResults();
this.__validationResult = []; this.__finishValidation({ source: 'sync', hasAsync: true });
this._updateFeedbackComponent(); this._updateFeedbackComponent();
return; return;
} }

View file

@ -380,7 +380,36 @@ describe('<lion-field>', () => {
expect(el.validationStates.error).to.have.a.property('HasX'); expect(el.validationStates.error).to.have.a.property('HasX');
expect(disabledEl.hasFeedbackFor).to.deep.equal([]); 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}
</${tag}>
`);
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 () => { it('can be required', async () => {