blazor-devexpress-dot-blazor-dot-dxcombobox-2-f65fcdf0.md
Fires when the ComboBox editor’s text is being modified. Use this event to validate/cancel user input or item selection.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
[Parameter]
public Action<ParameterValueChangingEventArgs<string>> TextChanging { get; set; }
The TextChanging event's data class is ParameterValueChangingEventArgs<String>. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| NewValue | Gets or sets the new value being assigned to the parameter. |
| OldValue | Gets the current parameter value. |
The ComboBox editor raises the TextChanging event before the TextChanged event. Both events fire when a user performs one of the following actions:
You can use the TextChanging event to validate/cancel user input or item selection. In the following example, the TextChanging event is used to validate text input with two rules:
Invalid text is not applied. Valid text changes are handled in the TextChanged event handler.
<DxComboBox Data="@Cities"
TValue="string"
TData="string"
AllowUserInput="true"
SearchMode="ListSearchMode.AutoSearch"
Text="@Text"
TextChanging="@OnTextChanging"
TextChanged="@OnTextChanged">
</DxComboBox>
<div class="mt-2">
Current text: <b>@Text</b>
</div>
@code {
List<string> Cities = new() {
"New York",
"London",
"Berlin",
"Paris",
"Tokyo"
};
string Text { get; set; } = "London";
void OnTextChanging(ParameterValueChangingEventArgs<string> e) {
// Prevent entering numbers in the text
if (e.NewValue != null && e.NewValue.Any(char.IsDigit)) {
e.NewValue = e.OldValue;
return;
}
// Limit text length to 15 characters
if (e.NewValue?.Length > 15) {
e.NewValue = e.OldValue;
return;
}
}
void OnTextChanged(string newValue) {
Text = newValue;
}
}
See Also
DxComboBox<TData, TValue> Class