Here is an example that shows how to select the day portion of the DateInput after the user hits Backspace. The code can be adjusted to handle other key presses or other textbox values.
@inject IJSRuntime js
<span @onkeydown="@OnKeyDown">
<TelerikDatePicker @bind-Value="@DateValue"
DebounceDelay="1500"
Format="dd-MM-yyyy"
Width="300px"
Id="d1">
<DatePickerFormatPlaceholder Year="jjjj" Month="mm" Day="dd"></DatePickerFormatPlaceholder>
</TelerikDatePicker>
</span>
<!-- move this script to a separate file in a real app -->
<script suppress-error="BL9992">//
function selectDaySegment(inputId) {
setTimeout(function() {
var focusedElement = document.activeElement;
var dateInput = document.querySelector("#" + inputId);
if (focusedElement == dateInput && dateInput.value == "dd-mm-jjjj") {
dateInput.setSelectionRange(0, 2);
}
});
}
//</script>
@code {
DateTime? DateValue { get; set; } = DateTime.Now;
async Task OnKeyDown(KeyboardEventArgs args)
{
if (args.Key == "Backspace")
{
await js.InvokeVoidAsync("selectDaySegment", "d1");
}
}
}