Skip to main content

ComboBoxValidateBy Enum

Lists values that define which ComboBox property is used for input validation.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.1.dll

NuGet Package: DevExpress.Blazor

Declaration

public enum ComboBoxValidateBy

Members

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.

Related API Members

The following properties accept/return ComboBoxValidateBy values:

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

ComboBox Validation

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

See Also