Fix Blazor client-side validation support for custom attributes - #69020
Merged
Conversation
…stom validator registration
…eration to support derived built-in attributes
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The reviewed changes are covered by targeted tests with no unresolved issues.
Pull request overview
Fixes Blazor SSR custom client-side validation registration and rule-provider precedence.
Changes:
- Initializes
Blazor.formValidationduring startup. - Prioritizes custom rules over inherited built-in mappings.
- Adds unit and E2E coverage.
File summaries
| File | Change |
|---|---|
src/Components/Web.JS/test/Validation/Adapters/BlazorAdapter.test.ts |
Tests validator registration before forms exist. |
src/Components/Web.JS/src/Validation/Adapters/BlazorAdapter.ts |
Creates the validation service unconditionally. |
src/Components/Web.JS/src/Boot.Web.ts |
Initializes validation during startup. |
src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/Forms/ClientValidation/CustomValidator.razor.js |
Defines the test validator. |
src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/Forms/ClientValidation/CustomValidator.razor |
Loads the validator module. |
src/Components/test/E2ETest/ServerRenderingTests/ClientValidation/ClientValidationTest.cs |
Covers startup availability and custom validation. |
src/Components/Endpoints/test/FormValidation/ClientValidationProviderTests.cs |
Tests custom-provider precedence. |
src/Components/Endpoints/src/Forms/DataAnnotationsClientValidationProvider.cs |
Evaluates custom providers before built-in mappings. |
Review details
- Files reviewed: 8/8 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
javiercn
approved these changes
Sep 3, 2026
Member
Author
|
/backport to release/11.0 |
Contributor
|
Started backporting to |
10 tasks
lewing
pushed a commit
that referenced
this pull request
Sep 4, 2026
…) (#69026) * Fix Blazor client-side validation initialization to better support custom validator registration * Try IClientValidationRuleProvider first in client validation rule generation to support derived built-in attributes Co-authored-by: Ondřej Roztočil <roztocil@outlook.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes two problems in support for custom validation attributes in the Blazor SSR client-side validation feature.
1. JS validator registration timing: As an optimization,
Blazor.formValidationwas only created when the loaded page already contained the custom element carrying the rules, and only atDOMContentLoaded. So an app could not register custom validators from its startup code on a page with no validated form. For example, trying to register the custom validator in the continuation ofBlazor.start().then(...)did not work and threw. This made use of custom validators difficult and unintuitive. After this fix, theBlazor.formValidationAPI is fully available immediately afterBlazor.startruns.2. Emitting rules for derived built-in attributes: An attribute deriving from a built-in one (for example
RequiredIfAttribute : RequiredAttribute) had itsIClientValidationRuleProviderrules silently discarded, because the built-in mapping matched the base type first and short-circuited. After this fix, custom rule providers take precedence over the built-in mapping.Adds/updates tests to cover the new behavior.