Skip to content

Add .NET 10/11 validation samples and align FieldCssClassProvider style - #662

Draft
oroztocil wants to merge 1 commit into
mainfrom
copilot/net10-net11-validation-samples
Draft

Add .NET 10/11 validation samples and align FieldCssClassProvider style#662
oroztocil wants to merge 1 commit into
mainfrom
copilot/net10-net11-validation-samples

Conversation

@oroztocil

Copy link
Copy Markdown
Member

Adds two sample projects that back code references in the Blazor forms validation articles, and aligns three existing provider samples with the style used across those articles.

New: 10.0/BlazorWebAppRemoteValidation

A three-project solution for the remote validation walkthrough, which previously carried all of its code inline in the article:

Project Contents
BlazorSample Server form validator and the proxy endpoint
BlazorSample.Client Model, validation abstraction, client form validator, CustomValidation component, Starship10 form
MinimalApiJwt The remote validation endpoint

The layout and namespaces match what the article instructs readers to create, so the code in the sample is the code in the walkthrough.

This also fills a gap: Starship1 through Starship14 were already samples except Starship10, which was the only form in the article family that was inlined.

New: 11.0/BlazorSample_BlazorWebApp

Covers the validation features introduced in .NET 11:

  • StartsWithAttribute - a custom validation attribute that also supplies a client-side rule for static SSR forms.
  • wwwroot/BlazorSample.lib.module.js - a JavaScript initializer that registers the matching client-side validator.
  • UsernameUniquenessValidator - asynchronous validation registered both for the whole form and per field.
  • AsyncValidation page - displays pending and faulted validation state.

Changed: CustomFieldClassProvider and CustomFieldClassProvider2 (8.0, 9.0, 10.0)

The three provider samples form a progression: style all fields, style one field, then apply Blazor's default classes to the rest. They previously used three different shapes for the same concept, which made incidental style the most visible difference between them. They now share one shape, so the only thing that varies is the behavior being demonstrated.

CustomFieldClassProvider3 already used this shape and is unchanged.

Verification

Both solutions build with no errors and no warnings.

The remote validation endpoint was exercised end to end with authentication mocked out:

Request Result
Valid model 204 No Content
Defense ship with no description 400 with the business-rule error
Identifier too long, accommodation out of range 400 with both field errors

The third case confirms AddValidation runs and validates data annotations before the handler.

The .NET 11 static SSR form was rendered and checked to confirm:

  • The client validation metadata is emitted, including the custom rule and its parameters.
  • The framework attaches each rule's resolved error message.
  • The payload is encoded safely in the page.
  • Both the per-form and the app-wide opt-out suppress the metadata, and server-side validation continues to run when they do.

Notes

  • The remote validation sample builds and its projects are wired together, but it is not configured against a real identity provider. Running it end to end requires the same identity configuration as the other samples that use MinimalApiJwt.
  • The .Client project needs a Microsoft.Extensions.Http package reference for the typed HttpClient registration used by the walkthrough.

Adds two sample projects that back code references in the Blazor forms
validation articles, and aligns three existing provider samples with the
style used across the validation docs.

New: 10.0/BlazorWebAppRemoteValidation

A three-project solution for the remote validation walkthrough:

* BlazorSample: server project with the server form validator and the
  proxy endpoint.
* BlazorSample.Client: model, validation abstraction, client form
  validator, CustomValidation component, and the Starship10 form.
* MinimalApiJwt: the remote validation endpoint.

New: 11.0/BlazorSample_BlazorWebApp

Covers validation features introduced in .NET 11:

* StartsWithAttribute: a custom validation attribute that also supplies a
  client-side rule for static SSR forms.
* A JavaScript initializer that registers the matching client validator.
* UsernameUniquenessValidator: asynchronous validation registered both for
  the whole form and per field.
* AsyncValidation page: displays pending and faulted validation state.

Changed: CustomFieldClassProvider and CustomFieldClassProvider2 (8.0, 9.0, 10.0)

The three provider samples form a progression, so they now share one shape,
which makes the difference between them the only thing that varies.

Verification

Both solutions build with no errors or warnings. The remote validation
endpoint was exercised for a valid model, a business-rule failure, and data
annotations failures. The .NET 11 static SSR form was checked to confirm the
client validation metadata, including the custom rule, and that both the
per-form and global opt-outs suppress it while server-side validation
continues to run.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 608096b5-db3e-4006-adaa-b4da0309ff87
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.

1 participant