Skip to main content

DxComboBox<TData, TValue>.ValidateBy Property

Specifies which ComboBox property takes part in input validation.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v23.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 and Value properties are specified, the editor’s value is validated.

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 code below shows an example of display text validation:

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; }
    }
}

ComboBox Validation

For more information, refer to the following help topic: Validate Input.

See Also