-
-
Notifications
You must be signed in to change notification settings - Fork 9
Feature: Support FluentValidation warning/info severity in Blazor forms #76
Description
Problem
FluentValidation supports a Severity property on validation rules (Error, Warning, Info), but Blazilla currently treats all ValidationFailure results as errors — they all go into the ValidationMessageStore, which means:
- Warning-severity rules block form submission (because
EditContext.Validate()checksGetValidationMessages()) - No way to display warnings differently from errors (e.g. amber vs red styling)
- No way to show advisory messages that inform the user without preventing submission
This is a common need in business applications where some fields are "recommended but not required" — for example, showing "Description is recommended" as a warning while still allowing the form to submit.
Proposed Solution
Route non-error severity failures to an EditContext.Properties side-channel instead of the ValidationMessageStore. This is a non-breaking change — existing error behavior is completely untouched.
The core idea:
- In
ApplyValidationResults, checkvalidationFailure.Severity— only addSeverity.Errorfailures to theValidationMessageStore - Store warning/info failures in
EditContext.Propertiesvia a small static helper class - Provide extension methods on
EditContextto retrieve warnings (GetWarnings,GetAllWarnings,HasWarnings) - Optionally provide a
WarningValidationMessage<TValue>component analogous toValidationMessage<TValue>that reads from the warnings side-channel
I've successfully implemented this approach in a fork of the Blazored.FluentValidation library (v2.2.0) and have been using it in production. The changes are well-contained and the approach works reliably with both sync and async validation, field-level and model-level validation, and mixed error/warning rule sets.
Happy to submit a PR if there's interest.