fix(field): remove validation toggled disable
when disable is toggled to true, validation should be removed
This commit is contained in:
parent
469c3bd667
commit
e24f2efcff
2 changed files with 31 additions and 2 deletions
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue