Nop 4.20, fluentValidation update to AddressValidator.cs. Chaining of .When() & others not called.

8 months ago
Hi,

I have a edited a fluent validation rulefor within Validators/Common/AddressValidator.cs.

I changed the base nop code from:


            if (addressSettings.ZipPostalCodeRequired && addressSettings.ZipPostalCodeEnabled)
            {
                RuleFor(x => x.ZipPostalCode).NotEmpty().WithMessage(localizationService.GetResource("Account.Fields.ZipPostalCode.Required"));
            }


To:


            if (addressSettings.ZipPostalCodeRequired && addressSettings.ZipPostalCodeEnabled)
            {
                RuleFor(x => x.ZipPostalCode).NotEmpty().WithMessage(localizationService.GetResource("Account.Fields.ZipPostalCode.Required")).When(x=>x.ZipPostalCodeRequired);
            }


By adding
 .When(x=>x.ZipPostalCodeRequired); 
as described on your documentation HERE.

This results in no validation, even though the condition is met. I've tried all fluent validation validators chaining from .NotEmpty() and none of them work.

Is this a bug?
8 months ago
Went with server side validation, I found that you can only use a few Validators as client-side, via the fluentvalidation docs.
8 months ago
Yes when validation work on server side. bcz its dynamic validation condition so