Demos About Radzen
Search Results for

    Show / Hide Table of Contents

    Class RadzenRequiredValidator

    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<TItem> 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
    IDisposable
    IRadzenFormValidator
    Inherited Members
    ValidatorBase.messages
    ValidatorBase.SetParametersAsync(ParameterView)
    ValidatorBase.GetComponentCssClass()
    ValidatorBase.Dispose()
    ValidatorBase.BuildRenderTree(RenderTreeBuilder)
    ValidatorBase.Form
    ValidatorBase.Component
    ValidatorBase.Popup
    ValidatorBase.IsValid
    ValidatorBase.EditContext
    RadzenComponent.OnMouseEnter()
    RadzenComponent.OnMouseLeave()
    RadzenComponent.OnContextMenu(MouseEventArgs)
    RadzenComponent.GetCssClass()
    RadzenComponent.GetId()
    RadzenComponent.Debounce(Func<Task>, int)
    RadzenComponent.OnInitialized()
    RadzenComponent.OnAfterRenderAsync(bool)
    RadzenComponent.RaiseContextMenu(MouseEventArgs)
    RadzenComponent.RaiseMouseEnter()
    RadzenComponent.AddContextMenu()
    RadzenComponent.RaiseMouseLeave()
    RadzenComponent.Attributes
    RadzenComponent.Element
    RadzenComponent.MouseEnter
    RadzenComponent.MouseLeave
    RadzenComponent.ContextMenu
    RadzenComponent.Culture
    RadzenComponent.DefaultCulture
    RadzenComponent.Style
    RadzenComponent.Visible
    RadzenComponent.UniqueID
    RadzenComponent.JSRuntime
    RadzenComponent.IsJSRuntimeAvailable
    RadzenComponent.Reference
    RadzenComponent.CurrentStyle
    ComponentBase.OnInitializedAsync()
    ComponentBase.OnParametersSet()
    ComponentBase.OnParametersSetAsync()
    ComponentBase.StateHasChanged()
    ComponentBase.ShouldRender()
    ComponentBase.OnAfterRender(bool)
    ComponentBase.InvokeAsync(Action)
    ComponentBase.InvokeAsync(Func<Task>)
    ComponentBase.DispatchExceptionAsync(Exception)
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: Radzen.Blazor
    Assembly: Radzen.Blazor.dll
    Syntax
    public class RadzenRequiredValidator : ValidatorBase, IComponent, IHandleEvent, IHandleAfterRender, IDisposable, 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

    RadzenRequiredValidator()

    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<TItem> 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()
    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" />

    Properties

    DefaultValue

    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
    [Parameter]
    public object DefaultValue { get; set; }
    Property Value
    Type Description
    object

    The value to treat as empty/invalid. Default is null.

    Text

    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
    [Parameter]
    public override string Text { get; set; }
    Property Value
    Type Description
    string

    The validation error message. Default is "Required".

    Overrides
    ValidatorBase.Text

    Methods

    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

    true if validation is successful, false otherwise.

    Overrides
    ValidatorBase.Validate(IRadzenFormComponent)

    Implements

    IComponent
    IHandleEvent
    IHandleAfterRender
    IDisposable
    IRadzenFormValidator

    Introducing Radzen Blazor Studio

    Radzen Blazor Studio is a software development environment that empowers developers to design, build and deploy Blazor applications without the traditional hurdles. Write less code and get more done.

    Learn More

    Download Now
    Download Now
    In This Article
    Back to top Radzen Blazor Components, © 2018-2025 Radzen. Source Code licensed under MIT