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.
ValidatorBase.SetParametersAsync
ValidatorBase.GetComponentCssClass
RadzenComponent.OnAfterRenderAsync
RadzenComponent.RaiseContextMenu
RadzenComponent.RaiseMouseEnter
RadzenComponent.AddContextMenu
RadzenComponent.RaiseMouseLeave
RadzenComponent.OnBecameInvisible
RadzenComponent.DefaultCulture
RadzenComponent.IsJSRuntimeAvailable
ComponentBase.OnInitializedAsync
ComponentBase.OnParametersSet
ComponentBase.OnParametersSetAsync
ComponentBase.StateHasChanged
ComponentBase.ShouldRender
ComponentBase.OnAfterRender
ComponentBase.InvokeAsync
ComponentBase.DispatchExceptionAsync
ComponentBase.RendererInfo
ComponentBase.Assets
ComponentBase.AssignedRenderMode
Namespace: Radzen.Blazor
Assembly: Radzen.Blazor.dll
public class RadzenRequiredValidator : ValidatorBase, IComponent, IHandleEvent, IHandleAfterRender, IRadzenFormValidatorBasic 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" />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.
public RadzenRequiredValidator()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.
public object DefaultValue { get; set; }
| Type | Description |
|---|---|
| object | 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. |
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.
public string Text { get; set; }
| Type | Description |
|---|---|
| string | 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. |
protected override bool Validate(IRadzenFormComponent component)
| Type | Name | Description |
|---|---|---|
| IRadzenFormComponent | component |
| Type | Description |
|---|---|
| bool |