[Solved] Select entire date input on click

1 Answer 15 Views
DateInput DatePicker TimePicker
neelima
Top achievements
Rank 1
neelima asked on 18 Mar 2026, 03:18 PM
When user clicks on the input field of DatePicker, it either select date, or month, or year, but we want to select whole date input field and start from first input (dd or MM or YYYY) and move to next field.

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 19 Mar 2026, 02:58 PM

Hello Neelima,

You can use JSInterop to select the whole textbox content on focus, as per the example below. Please note that the desired behavior conflicts with a built-in behavior, so you need a JavaScript timeout.

Also, please ask the license holder at your company to assign you an active license. This will ensure your Telerik account is compliant to our license agreement and will entitle you to technical support.

@implements IDisposable
@inject IJSRuntime JS

<TelerikDatePicker @bind-Value="@DatePickerValue" Width="200px" Class="select-on-focus" />

<TelerikDatePicker @bind-Value="@DatePickerValue" Width="200px" Class="select-on-focus" />

<script>
    function attachFocusHandler() {
        var inputsToSelect = document.querySelectorAll(".select-on-focus input");
        inputsToSelect.forEach((element) => {
            element.addEventListener("focus", onInputSelect);
        });
    }

    function detachFocusHandler() {
        var inputsToSelect = document.querySelectorAll(".select-on-focus input");
        inputsToSelect.forEach((element) => {
            element.removeEventListener("focus", onInputSelect);
        });
    }

    function onInputSelect(e) {
        setTimeout(() => {
            e.target.select();
        }, 100); // use the smallest delay that works reliably
    }
</script>

@code {
    private DateTime DatePickerValue { get; set; } = DateTime.Today;

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            await Task.Delay(1);
            await JS.InvokeVoidAsync("attachFocusHandler");
        }

        await base.OnAfterRenderAsync(firstRender);
    }

    public void Dispose()
    {
        _ = JS.InvokeVoidAsync("detachFocusHandler");
    }
}

Regards,
Dimo
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
DateInput DatePicker TimePicker
Asked by
neelima
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or