Validation issue RadzenCompareValidator #1213

Closed
opened 2026-01-29 17:50:32 +00:00 by claunia · 1 comment
Owner

Originally created by @hkaya-camas on GitHub (Apr 26, 2024).

Bug description
A bug in the RadzenCompareValidator triggers all validation in the TemplateForm. Specifically, this happens when the Value parameter of the RadzenCompareValidator changes during the lifecycle of the component.

Example code

@page "/CompareValidatorIssue"

<Radzen.Blazor.RadzenTemplateForm @ref="registrationForm" TItem="EmployeeRegistration" Data=@employeeRegistration>
    <div>
        <Radzen.Blazor.RadzenLabel Text="Username"></Radzen.Blazor.RadzenLabel>
        <Radzen.Blazor.RadzenTextBox @bind-Value=@employeeRegistration!.Username Name="Username" />
        <Radzen.Blazor.RadzenRequiredValidator Component="Username" Text="Username is required." />
    </div>

    <div>
        <Radzen.Blazor.RadzenLabel Text="Password"></Radzen.Blazor.RadzenLabel>
        <Radzen.Blazor.RadzenTextBox @bind-Value=@employeeRegistration!.Password Name="Password" />
        <Radzen.Blazor.RadzenLengthValidator Component="Password" Text="Minimum length 6." Min="6" />
        <Radzen.Blazor.RadzenRequiredValidator Component="Password" Text="Password is required." />
    </div>

    <div>
        <Radzen.Blazor.RadzenLabel Text="Repeat password"></Radzen.Blazor.RadzenLabel>
        <Radzen.Blazor.RadzenTextBox @bind-Value=@employeeRegistration!.RepeatPassword Name="RepeatPassword" />
        <Radzen.Blazor.RadzenCompareValidator Value="@employeeRegistration!.Password" Component="RepeatPassword" Text="New password and repeat password do not match." />
    </div>

    <div>
        <Radzen.Blazor.RadzenButton ButtonType="Radzen.ButtonType.Submit" Click=EndRegistrationPage Text="Register account" />
    </div>
</Radzen.Blazor.RadzenTemplateForm>

@code {
    public class EmployeeRegistration
    {
        public string? Username { get; set; } = string.Empty;
        public string? Password { get; set; } = string.Empty;
        public string? RepeatPassword { get; set; } = string.Empty;
    }

    private Radzen.Blazor.RadzenTemplateForm<EmployeeRegistration> registrationForm = default!;
    private EmployeeRegistration? employeeRegistration { get; set; }

    protected override async Task OnInitializedAsync()
    {
        employeeRegistration = new EmployeeRegistration();
        await base.OnInitializedAsync();
    }

    private void EndRegistrationPage()
    {
        registrationForm.EditContext?.Validate();
    }
}

Reproduction

  1. Run the code above (or something similair)
  2. Click on the Password field
  3. Type something
  4. Click outside the field
  5. Perform the last 3 steps again
  6. Result: All validation gets triggered

Recording:

https://github.com/radzenhq/radzen-blazor/assets/139757659/c05631c1-2098-4926-9c58-3cf603b66504

Expected behavior
Only the edited field gets validated.

Originally created by @hkaya-camas on GitHub (Apr 26, 2024). **Bug description** A bug in the RadzenCompareValidator triggers all validation in the TemplateForm. Specifically, this happens when the Value parameter of the RadzenCompareValidator changes during the lifecycle of the component. **Example code** ``` @page "/CompareValidatorIssue" <Radzen.Blazor.RadzenTemplateForm @ref="registrationForm" TItem="EmployeeRegistration" Data=@employeeRegistration> <div> <Radzen.Blazor.RadzenLabel Text="Username"></Radzen.Blazor.RadzenLabel> <Radzen.Blazor.RadzenTextBox @bind-Value=@employeeRegistration!.Username Name="Username" /> <Radzen.Blazor.RadzenRequiredValidator Component="Username" Text="Username is required." /> </div> <div> <Radzen.Blazor.RadzenLabel Text="Password"></Radzen.Blazor.RadzenLabel> <Radzen.Blazor.RadzenTextBox @bind-Value=@employeeRegistration!.Password Name="Password" /> <Radzen.Blazor.RadzenLengthValidator Component="Password" Text="Minimum length 6." Min="6" /> <Radzen.Blazor.RadzenRequiredValidator Component="Password" Text="Password is required." /> </div> <div> <Radzen.Blazor.RadzenLabel Text="Repeat password"></Radzen.Blazor.RadzenLabel> <Radzen.Blazor.RadzenTextBox @bind-Value=@employeeRegistration!.RepeatPassword Name="RepeatPassword" /> <Radzen.Blazor.RadzenCompareValidator Value="@employeeRegistration!.Password" Component="RepeatPassword" Text="New password and repeat password do not match." /> </div> <div> <Radzen.Blazor.RadzenButton ButtonType="Radzen.ButtonType.Submit" Click=EndRegistrationPage Text="Register account" /> </div> </Radzen.Blazor.RadzenTemplateForm> @code { public class EmployeeRegistration { public string? Username { get; set; } = string.Empty; public string? Password { get; set; } = string.Empty; public string? RepeatPassword { get; set; } = string.Empty; } private Radzen.Blazor.RadzenTemplateForm<EmployeeRegistration> registrationForm = default!; private EmployeeRegistration? employeeRegistration { get; set; } protected override async Task OnInitializedAsync() { employeeRegistration = new EmployeeRegistration(); await base.OnInitializedAsync(); } private void EndRegistrationPage() { registrationForm.EditContext?.Validate(); } } ``` **Reproduction** 1. Run the code above (or something similair) 2. Click on the Password field 3. Type something 4. Click outside the field 5. Perform the last 3 steps again 6. Result: All validation gets triggered Recording: https://github.com/radzenhq/radzen-blazor/assets/139757659/c05631c1-2098-4926-9c58-3cf603b66504 **Expected behavior** Only the edited field gets validated.
Author
Owner

@enchev commented on GitHub (Apr 29, 2024):

Hi @hkaya-camas,

I've just pushed a change that will validate only this validator on component value change not the entire EditContext. There is also ValidateOnComponentValueChange property which can be set to false if you do not want validation on value change.

@enchev commented on GitHub (Apr 29, 2024): Hi @hkaya-camas, I've just pushed a change that will validate only this validator on component value change not the entire EditContext. There is also ValidateOnComponentValueChange property which can be set to false if you do not want validation on value change.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1213