Skip to content

Commit

Permalink
fix: validate custom-field when required is set to false
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan committed Oct 2, 2024
1 parent fd28a42 commit 4139c6d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/custom-field/src/vaadin-custom-field-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,21 @@ export const CustomFieldMixin = (superClass) =>
return true;
}

/**
* Override an observer from `FieldMixin`
* to validate when required is removed.
*
* @protected
* @override
*/
_requiredChanged(required) {
super._requiredChanged(required);

if (required === false) {
this.validate();
}
}

/**
* @param {KeyboardEvent} e
* @protected
Expand Down
7 changes: 7 additions & 0 deletions packages/custom-field/test/validation.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,12 @@ describe('validation', () => {
fire(customField.inputs[0], 'change');
expect(customField.invalid).to.be.true;
});

it('should validate when setting required to false', async () => {
const validateSpy = sinon.spy(customField, 'validate');
customField.required = false;
await nextUpdate(customField);
expect(validateSpy).to.be.calledOnce;
});
});
});

0 comments on commit 4139c6d

Please sign in to comment.