Class RadzenCompareValidator
A validator component that compares a form input's value against another value or another component's value using a specified comparison operator. RadzenCompareValidator is commonly used for password confirmation, numeric range validation, or ensuring field values match expected criteria. Must be placed inside a RadzenTemplateForm<TItem> and associated with a named input component. Supports various comparison operations (Equal, NotEqual, GreaterThan, LessThan, etc.) via the Operator property. For password confirmation scenarios, set the Value property to the password field and the Component to the confirmation field name. Can react to changes in the comparison value by setting ValidateOnComponentValueChange to true (default).
Inherited Members
Namespace: Radzen.Blazor
Assembly: Radzen.Blazor.dll
Syntax
public class RadzenCompareValidator : ValidatorBase, IComponent, IHandleEvent, IHandleAfterRender, IDisposable, IRadzenFormValidator
Examples
<RadzenTemplateForm TItem="Model" Data=@model>
<RadzenPassword style="display: block" Name="Password" @bind-Value=@model.Password />
<RadzenPassword style="display: block" Name="RepeatPassword" @bind-Value=@model.RepeatPassword />
<RadzenCompareValidator Value=@model.Password Component="RepeatPassword" Text="Passwords should be the same" Style="position: absolute" />
</RadzenTemplateForm>
@code {
class Model
{
public string Password { get; set; }
public double Value { get; set; }
public string RepeatPassword { get; set; }
}
Model model = new Model();
}
Constructors
RadzenCompareValidator()
A validator component that compares a form input's value against another value or another component's value using a specified comparison operator. RadzenCompareValidator is commonly used for password confirmation, numeric range validation, or ensuring field values match expected criteria. Must be placed inside a RadzenTemplateForm<TItem> and associated with a named input component. Supports various comparison operations (Equal, NotEqual, GreaterThan, LessThan, etc.) via the Operator property. For password confirmation scenarios, set the Value property to the password field and the Component to the confirmation field name. Can react to changes in the comparison value by setting ValidateOnComponentValueChange to true (default).
Declaration
public RadzenCompareValidator()
Examples
<RadzenTemplateForm TItem="Model" Data=@model>
<RadzenPassword style="display: block" Name="Password" @bind-Value=@model.Password />
<RadzenPassword style="display: block" Name="RepeatPassword" @bind-Value=@model.RepeatPassword />
<RadzenCompareValidator Value=@model.Password Component="RepeatPassword" Text="Passwords should be the same" Style="position: absolute" />
</RadzenTemplateForm>
@code {
class Model
{
public string Password { get; set; }
public double Value { get; set; }
public string RepeatPassword { get; set; }
}
Model model = new Model();
}
Properties
Operator
Specifies the comparison operator. Set to CompareOperator.Equal by default.
Declaration
[Parameter]
public CompareOperator Operator { get; set; }
Property Value
| Type | Description |
|---|---|
| CompareOperator |
Text
Gets or sets the message displayed when the component is invalid. Set to "Value should match" by default.
Declaration
[Parameter]
public override string Text { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Overrides
ValidateOnComponentValueChange
Gets or sets a value indicating whether this RadzenCompareValidator should be validated on value change of the specified Component.
Declaration
[Parameter]
public virtual bool ValidateOnComponentValueChange { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
|
Value
Specifies the value to compare with.
Declaration
[Parameter]
public object Value { get; set; }
Property Value
| Type | Description |
|---|---|
| object |
Methods
OnAfterRender(bool)
A validator component that compares a form input's value against another value or another component's value using a specified comparison operator. RadzenCompareValidator is commonly used for password confirmation, numeric range validation, or ensuring field values match expected criteria. Must be placed inside a RadzenTemplateForm<TItem> and associated with a named input component. Supports various comparison operations (Equal, NotEqual, GreaterThan, LessThan, etc.) via the Operator property. For password confirmation scenarios, set the Value property to the password field and the Component to the confirmation field name. Can react to changes in the comparison value by setting ValidateOnComponentValueChange to true (default).
Declaration
protected override void OnAfterRender(bool firstRender)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | firstRender |
Overrides
SetParametersAsync(ParameterView)
Called by the Blazor runtime when parameters are set.
Declaration
public override Task SetParametersAsync(ParameterView parameters)
Parameters
| Type | Name | Description |
|---|---|---|
| ParameterView | parameters | The parameters. |
Returns
| Type | Description |
|---|---|
| Task |
Overrides
Validate(IRadzenFormComponent)
Runs validation against the specified component.
Declaration
protected override bool Validate(IRadzenFormComponent component)
Parameters
| Type | Name | Description |
|---|---|---|
| IRadzenFormComponent | component | The component to validate. |
Returns
| Type | Description |
|---|---|
| bool |
|