RadzenRequiredValidator Class

A validator component that ensures a form input component has a non-empty value. RadzenRequiredValidator verifies that required fields are filled before form submission. Must be placed inside a RadzenTemplateForm<T> and associated with a named input component. Checks if the associated component has a value (HasValue returns true) and that the value is not equal to the optional DefaultValue. For text inputs, an empty string is considered invalid. For dropdowns and other components, null or default values are considered invalid. The validation message can be customized via the Text property and displayed inline, as a block, or as a popup depending on the Style property.

Inheritance

Object

ComponentBase

RadzenComponent

ValidatorBase

RadzenRequiredValidator

Implements

IComponent

IHandleEvent

IHandleAfterRender

IRadzenFormValidator

Namespace: Radzen.Blazor

Assembly: Radzen.Blazor.dll

Syntax

public class RadzenRequiredValidator : ValidatorBase, IComponent, IHandleEvent, IHandleAfterRender, IRadzenFormValidator

Examples

Basic required field validation:

<RadzenTemplateForm TItem="Model" Data=@model>
  <RadzenTextBox style="display: block" Name="Email" @bind-Value=@model.Email />
  <RadzenRequiredValidator Component="Email" Text="Email is required" Style="position: absolute" />
</RadzenTemplateForm>
@code {
 class Model
 {
   public string Email { get; set; }
 }

 Model model = new Model();
}

Dropdown validation with default value:

<RadzenDropDown Name="Country" @bind-Value=@model.CountryId Data=@countries />
<RadzenRequiredValidator Component="Country" DefaultValue="0" Text="Please select a country" />

Constructors

RadzenRequiredValidatorlink

A validator component that ensures a form input component has a non-empty value. RadzenRequiredValidator verifies that required fields are filled before form submission. Must be placed inside a RadzenTemplateForm<T> and associated with a named input component. Checks if the associated component has a value (HasValue returns true) and that the value is not equal to the optional DefaultValue. For text inputs, an empty string is considered invalid. For dropdowns and other components, null or default values are considered invalid. The validation message can be customized via the Text property and displayed inline, as a block, or as a popup depending on the Style property.

Declaration
public RadzenRequiredValidator()

Properties

DefaultValuelink

Gets or sets a default value that should be considered invalid (empty). For example, set to 0 for numeric dropdowns where 0 represents "not selected", or empty Guid for Guid fields. If the component's value equals this DefaultValue, validation will fail.

Declaration
public object DefaultValue { get; set; }
Property Value
Type Description
objectGets or sets a default value that should be considered invalid (empty). For example, set to 0 for numeric dropdowns where 0 represents "not selected", or empty Guid for Guid fields. If the component's value equals this DefaultValue, validation will fail.

Textlink

Gets or sets the error message displayed when the associated component is invalid (has no value or has the default value). This message helps users understand what is required to pass validation.

Declaration
public string Text { get; set; }
Property Value
Type Description
stringGets or sets the error message displayed when the associated component is invalid (has no value or has the default value). This message helps users understand what is required to pass validation.

Methods

Validatelink

Declaration
protected override bool Validate(IRadzenFormComponent component)
Parameters
Type Name Description
IRadzenFormComponent component
Returns
Type Description
bool
An error has occurred. This app may no longer respond until reloaded. Reload 🗙