diff --git a/samples/BlazorServer/Pages/Index.razor b/samples/BlazorServer/Pages/Index.razor
index f227a9f..a72800f 100644
--- a/samples/BlazorServer/Pages/Index.razor
+++ b/samples/BlazorServer/Pages/Index.razor
@@ -5,7 +5,7 @@
-
+
@@ -72,6 +72,10 @@
@code {
private readonly Person _person = new();
private FluentValidationValidator? _fluentValidationValidator;
+ private readonly IDictionary _data = new Dictionary
+ {
+ { "MinAgeLimit", 18 }
+ };
private void SubmitValidForm()
=> Console.WriteLine("Form Submitted Successfully!");
diff --git a/samples/BlazorWebAssembly/Pages/Index.razor b/samples/BlazorWebAssembly/Pages/Index.razor
index 400e083..d1b1494 100644
--- a/samples/BlazorWebAssembly/Pages/Index.razor
+++ b/samples/BlazorWebAssembly/Pages/Index.razor
@@ -5,7 +5,7 @@
-
+
@@ -72,6 +72,10 @@
@code {
private readonly Person _person = new();
private FluentValidationValidator? _fluentValidationValidator;
+ private readonly IDictionary _data = new Dictionary
+ {
+ { "MinAgeLimit", 18 }
+ };
private async Task SubmitFormAsync()
{
diff --git a/samples/Shared/SharedModels/Person.cs b/samples/Shared/SharedModels/Person.cs
index 412ae40..6462dd6 100644
--- a/samples/Shared/SharedModels/Person.cs
+++ b/samples/Shared/SharedModels/Person.cs
@@ -28,6 +28,13 @@ public PersonValidator()
RuleFor(p => p.Age)
.NotNull().WithMessage("You must enter your age")
+ .Custom((age, context) =>
+ {
+ if (context.RootContextData.TryGetValue("MinAgeLimit", out var ageValue) && ageValue is int minAge && age < minAge)
+ {
+ context.AddFailure($"Age must be greater than {minAge}");
+ }
+ })
.GreaterThanOrEqualTo(0).WithMessage("Age must be greater than 0")
.LessThan(150).WithMessage("Age cannot be greater than 150");
diff --git a/src/Blazored.FluentValidation/EditContextFluentValidationExtensions.cs b/src/Blazored.FluentValidation/EditContextFluentValidationExtensions.cs
index c06c9f4..f90fa1e 100644
--- a/src/Blazored.FluentValidation/EditContextFluentValidationExtensions.cs
+++ b/src/Blazored.FluentValidation/EditContextFluentValidationExtensions.cs
@@ -23,7 +23,7 @@ public static void AddFluentValidation(this EditContext editContext, IServicePro
async (sender, _) => await ValidateModel((EditContext)sender!, messages, serviceProvider, disableAssemblyScanning, fluentValidationValidator, validator);
editContext.OnFieldChanged +=
- async (_, eventArgs) => await ValidateField(editContext, messages, eventArgs.FieldIdentifier, serviceProvider, disableAssemblyScanning, validator);
+ async (_, eventArgs) => await ValidateField(editContext, messages, eventArgs.FieldIdentifier, serviceProvider, disableAssemblyScanning, fluentValidationValidator, validator);
}
private static async Task ValidateModel(EditContext editContext,
@@ -52,6 +52,8 @@ private static async Task ValidateModel(EditContext editContext,
context = new ValidationContext