DxComboBox<TData, TValue>.TextChanging Event
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
Declaration
[Parameter]
public Action<ParameterValueChangingEventArgs<string>> TextChanging { get; set; }
Event Data
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. |
Remarks
The ComboBox editor raises the TextChanging event before the TextChanged event. Both events fire when a user performs one of the following actions:
- Changes the editor’s text and removes focus from the ComboBox.
- Changes the editor’s text and presses Enter.
- Clicks the Clear button.
- Selects an item from the ComboBox editor’s drop-down window.
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:
- Prevents entering numbers.
- Limits text length to 15 characters.
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;
}
}