Hello,
I’m trying to use a RadzenTextBox to make a searchbox (for an API call). I’d like 4 caracters before calling API and a min of 2msec but I never hit the OnTyping method. I tried several solutionb but still the same problem.
Do you have an idea ?
Thanks
I tried several solution like but for the moment I’m trying this one.
<RadzenTextBox @bind-Value="@ViewModel.Model.SearchString"
Change="OnTyping"
Name="Name"
Placeholder="Partial ref"
Style="width: 100%;"
MaxLength="100"
aria-label="Partial ref" />
private async Task OnTyping()
{
// Cancel any pending search
_searchCancellationTokenSource?.Cancel();
_searchCancellationTokenSource = new CancellationTokenSource();
if (ViewModel.Model.SearchString?.Length >= 4)
{
try
{
await Task.Delay(200, _searchCancellationTokenSource.Token);
await ViewModel.Search(0, 10);
}
catch (OperationCanceledException)
{
// ignore
}
}
StateHasChanged();
}