The FluentValidationValidator validates the Postcode field using the AddressValidator, even though the CompanyValidator for the Model does not reference the AddressValidator, and companyValidator.Validate() does not use the AddressValidator. The Postcode field should not be validated in this case.
Expected behavior
The validator for the Model (CustomerValidator) should be used for all field validations, company.Address.Postcode should not be validated as CustomerValidator does not reference AddressValidator.
Describe the bug Assume we have a complex type from this documentation: https://docs.fluentvalidation.net/en/latest/start.html#complex-properties
There is a
Customer
class with anAddress
property and two validators:CustomerValidator
andAddressValidator
.Let’s remove this line from the
CustomerValidator
:The
AddressValidator
still exists:Now, when you create this type of UI (shortened for brevity):
The
FluentValidationValidator
validates thePostcode
field using theAddressValidator
, even though theCompanyValidator
for theModel
does not reference theAddressValidator
, andcompanyValidator.Validate()
does not use theAddressValidator
. ThePostcode
field should not be validated in this case.Expected behavior The validator for the
Model
(CustomerValidator
) should be used for all field validations,company.Address.Postcode
should not be validated asCustomerValidator
does not referenceAddressValidator
.Additional context https://github.com/Blazored/FluentValidation/blob/f02c9beb6489574b91bb20c2a2257a6f2339eb67/src/Blazored.FluentValidation/EditContextFluentValidationExtensions.cs#L84-L105
I believe the issue is in how the
ValidateField()
method is implemented. It usesfieldIdentifier.Model
directly and does not takeeditContext.Model
into account. The implementation won’t be trivial (you cannot simply replacefieldIdentifier.Model
witheditContext.Model
as someone has already tried), but it is doable.Related items:
76
91
104
132
178
cc @jirikanda