Closed sven5 closed 4 years ago
On a glance, that code should run just fine. (That validation logic would be run normally by FluentValidation. I do not tamper with the behavior of any / async validations whatsoever)
Try following these basic troubleshooting guide:
If all fails, send a zip with minimum repro and I’ll take a quick look at it.
The method is running, but no validation message appears. Could you take a quick look into this? I've taken the example from https://github.com/mrpmorris/blazor-university/tree/master/src/Forms/CustomValidation
That... does not look like my library at all.
Are you sure that you are using my library? https://www.nuget.org/packages/Accelist.FluentValidation.Blazor
By the way, my library has a demo project which you can run here:
https://github.com/ryanelian/FluentValidation.Blazor/tree/master/Demo
Simply clone this repo https://github.com/ryanelian/FluentValidation.Blazor.git or download the zip: https://github.com/ryanelian/FluentValidation.Blazor/archive/master.zip
This demo project has a remote-simulated service:
public class EmailCheckerService
{
public async Task<bool> IsAvailableAsync(string email)
{
// simulate delay accessing remote services
await Task.Delay(1000);
if (email == "ryan.elian@accelist.com")
{
return await Task.FromResult(false);
}
return await Task.FromResult(true);
}
}
and a validator which uses such service:
public class FormModel2Validator : AbstractValidator<FormModel2>
{
private readonly EmailCheckerService EmailChecker;
public FormModel2Validator(EmailCheckerService emailCheckerService, IValidator<FormModel3> subValidator)
{
this.EmailChecker = emailCheckerService;
RuleFor(Q => Q.Email).Cascade(CascadeMode.StopOnFirstFailure)
.NotEmpty().MinimumLength(4).MaximumLength(64).EmailAddress()
.MustAsync(EmailAvailableAsync).WithMessage(o => $"Email {o.Email} is not available.");
RuleFor(Q => Q.FormModel3).SetValidator(subValidator);
RuleForEach(Q => Q.SubArray).SetValidator(subValidator);
}
public async Task<bool> EmailAvailableAsync(string email, System.Threading.CancellationToken cancellationToken)
{
return await EmailChecker.IsAvailableAsync(email);
}
}
which can be run:
I urge you to explore this demo project first.
That repo / project you gave me, it does not show
<PackageReference Include="Accelist.FluentValidation.Blazor" Version="2.1.0" />
in the csproj file: https://github.com/mrpmorris/blazor-university/blob/master/src/Forms/CustomValidation/CustomValidation.csproj
If you are depending on other FluentValidation libraries for Blazor, I suggest that you reach to the author of the said package.
Their package may have bugs / issues with async validation, which I'm not willing to debug.
Hi @ryanelian,
no need for frustration. I didn't say that it has something to do with your library. I just found your library while searching for async validation in Blazor and I still wonder how you got it working. I will give it a try.
Thanks Sven
Hi,
Currently, I'm struggling with async validation. I need to call a REST API to check something. My test code is
Do you have some experience how to get it working? Currently this just does nothing.