DxComboBox<TData, TValue>.ValidateBy Property
Specifies which ComboBox property takes part in input validation.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.2.dll
NuGet Package: DevExpress.Blazor
Declaration
[DefaultValue(ComboBoxValidateBy.Auto)]
[Parameter]
public ComboBoxValidateBy ValidateBy { get; set; }
Property Value
Type | Default | Description |
---|---|---|
ComboBoxValidateBy | Auto | A ComboBoxValidateBy enumeration value. |
Available values:
Name | Description |
---|---|
Auto | If the Text property is specified, the editor’s text is validated. If the Value property is specified, the editor’s value is validated. If both |
Text | The editor’s text is validated. |
Value | The editor’s value is validated. |
Remarks
DevExpress data entry components support the standard input validation mechanism. For more information, refer to the following Microsoft article: ASP.NET Core Blazor forms and validation.
Since value and display text may differ in a ComboBox component, you may need to specify which property is used for input validation. The following code snippet shows an example of display text validation:
- The
ValidateBy
property is set to ComboBoxValidateBy.Text. - The Text property’s bound field is marked with the StringLength(10) annotation attribute. It limits user input to 10 characters.
After a user select an item from the dropdown list or types in the edit box, the control displays red or green outline. Red indicates the editor value is longer than 10 characters. Green indicates the text is valid.
@using System.ComponentModel.DataAnnotations;
@inject WeatherForecastService ForecastService
<EditForm Model="weather">
<DataAnnotationsValidator />
<DxComboBox Data="forecasts"
TValue="WeatherForecast"
TData="WeatherForecast"
AllowUserInput="true"
Value="weather.Forecast"
Text="@weather.Summary"
ValueExpression="@(() => weather.Forecast)"
TextExpression="@(() => weather.Summary)"
ValueChanged="@ValueChanged"
TextChanged="@TextChanged"
TextFieldName="@nameof(WeatherForecast.Summary)"
ValidateBy="ComboBoxValidateBy.Text">
</DxComboBox>
</EditForm>
@code{
private WeatherForecast[] forecasts;
Day weather = new Day();
protected override async Task OnInitializedAsync() {
forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
weather.Forecast = forecasts.First();
}
void ValueChanged(WeatherForecast weather) {
this.weather.Forecast = weather;
}
void TextChanged(string text) {
weather.Summary = text;
}
class Day {
[StringLength(10)]
public string Summary { get; set; }
public WeatherForecast Forecast { get; set; }
}
}
For more information, refer to the following help topic: Validate Input.