Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add manual validation mode #8097

Merged
merged 22 commits into from
Nov 7, 2024
Merged

feat: add manual validation mode #8097

merged 22 commits into from
Nov 7, 2024

Conversation

vursen
Copy link
Contributor

@vursen vursen commented Nov 5, 2024

Description

The PR adds a manual validation mode that turns off automatic constraint validation, letting you control the validation process yourself. Constraint validation can still be triggered by calling validate() – particularly useful for cases where you want to delay any validation until a submit button is clicked. In manual validation mode, you can also set the invalid property directly through your application logic without conflicting with built-in validation.

Note

Instead of testing each validation case in every component, I decided to extend the no-restricted-syntax ESLint rule to make sure _requestValidation() is used instead of validate(). I believe this approach provides better protection, as tests won't catch any new validate() calls that may be added in the future.

Fixes #7902

Type of change

  • Feature

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Someone else might have opinions about the location of the plugin, but to me it looks fine as there isn't too much clutter otherwise at the moment. Can also easily be changed at any time.

@@ -0,0 +1,5 @@
{
"name": "eslint-plugin-local-rules",
"version": "1.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add "private": true to make sure this never gets published, then we don't need "version" field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced the custom implementation with no-restricted-syntax

* the `invalid` property directly through your application logic without conflicts
* with the component's internal validation.
*/
manualValidation: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add @attr {boolean} manual-validation annotation also to this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* @return {boolean}
*/
checkValidity() {
if (this.inputElement && this.inputElement.validate) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: We don't support iron form elements anymore.

if (this.inputElement.checkValidity) {
inputValidity = this.inputElement.checkValidity();
} else if (this.inputElement.validate) {
// Iron-form-elements have the validate API
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: We don't support iron form elements anymore.

.eslintrc.json Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Nov 7, 2024

@vursen vursen merged commit 9d96d20 into main Nov 7, 2024
9 checks passed
@vursen vursen deleted the feat/manual-validation branch November 7, 2024 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Manual validation mode
3 participants