1

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.

2
  • Just only set variables in OnInitialized method Commented Jun 24, 2024 at 5:03
  • you could try to manually trigger the events to make sure validation is working. revalidate form on submit e.g OnSubmit method call validation code. Use custom JavaScript to detect when autofill occurs and trigger the validation. This will check the values of the fields shortly after the page load and whenever the form is interacted with. Commented Jun 24, 2024 at 9:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.