Skip to content

Commit

Permalink
fix: validate custom-field when required is set to false (#7923)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored and vaadin-bot committed Oct 3, 2024
1 parent 79e40ce commit 87bc674
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 @@ -190,6 +190,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.test.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);

Check failure on line 104 in packages/custom-field/test/validation.test.js

View workflow job for this annotation

GitHub Actions / Lint

'nextUpdate' is not defined
expect(validateSpy).to.be.calledOnce;
});
});
});

0 comments on commit 87bc674

Please sign in to comment.