Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Problem after autocomplete in FluentValidation

$
0
0

If browser autocomplete two field in my register form (email + password) then validator always return true, but form has two others field (confirm password + terms). I can't find solution for this, because if i complete manually form, validator return false for incorrect fields.

Validator code:

public sealed class SignUpValidator : AbstractValidator<SignUpDataModel>{    public SignUpValidator(ITranslation translation)    {        RuleFor(x => x.Email).EmailAddress().WithMessage(translation["EMAIL_REQUIRED"]);        RuleFor(x => x.Password)            .NotEmpty().WithMessage(translation["PASSWORD_REQUIRED"]);        RuleFor(x => x.ConfirmPassword)            .NotEmpty()            .Must((m, password) => !string.IsNullOrEmpty(m.Password) && password.Equals(m.Password)).WithMessage(translation["PASSWORD_VARY"]);        RuleFor(x => x.AcceptTerms).Must(x => x).WithMessage(translation["ACCEPT_TERMS_REQUIRED"]);    }}

Method for OnSubmit in EditForm:

public async Task AcceptForm(EditContext context)    {        SuccessSignUp = false;        ErrorMessages = new string[]{};        IsValid = context.Validate();        if(!IsValid)            return;        IsBusy = true;        var result = await _apiResponseHandler.HandleAsync(            _identityService.SignUpAsync(new(DataModel.Email, DataModel.Password)), false);        IsBusy = false;        SuccessSignUp = result.Succeeded;        if (!result.Succeeded)        {            ErrorMessages = result.Errors.Select(x => x.Message);            IsValid = false;            return;        }    }

Others validators are ok, but only this one is break

I tried StateHasChanged in OnAfterRender, but dont work.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>