Closed kedzior-io closed 3 years ago
First of all, you don't need two validators in your EditForm. You also can't have two models. The validator validates the model provided to the EditForm. This will be why you're not seeing validation happening on the address, the validator knows nothing about it.
I would suggest checking out the example below which shows configuring a model with a nested validator. I would also suggest checking out the fluent validation documentation on the subject.
I have this form where I'm building up the list of addresses:
Here is the example: https://github.com/kedzior-io/blazor-webassmebly-aspnetcore-hosted-fluent-validation/blob/master/BlazorFluentValidation/Client/Pages/Index.razor
When I hit "Add Address" validation fires for first name and last name and completely ignores city and country.
When I remove:
<FluentValidationValidator Validator="AddressValidator" />
and instantiate validator manually:
it catches errors on address instance but it doesn't show it on the form below corresponding inputs.
Any idea why?
The only way I managed to get it working is splitting it into two forms (which is not ideal): https://github.com/kedzior-io/blazor-webassmebly-aspnetcore-hosted-fluent-validation/blob/master/BlazorFluentValidation/Client/Pages/Working.razor