Skip to content

Commit

Permalink
fix: validate custom-field when required is set to false (#7923) (#7927)
Browse files Browse the repository at this point in the history
Co-authored-by: Serhii Kulykov <[email protected]>
  • Loading branch information
vaadin-bot and web-padawan authored Oct 3, 2024
1 parent 80dca0d commit 52f6373
Show file tree
Hide file tree
Showing 2 changed files with 21 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
6 changes: 6 additions & 0 deletions packages/custom-field/test/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,11 @@ describe('validation', () => {
fire(customField.inputs[0], 'change');
expect(customField.invalid).to.be.true;
});

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

0 comments on commit 52f6373

Please sign in to comment.