Select the Day Segment in an Empty DateInput
Environment
- Product: Telerik UI for ASP.NET MVC DateInput
- Framework: ASP.NET MVC
- Client-side version tested: 2026.3.1015
- Browser tested: Chromium
Description
How can I position the cursor on the day segment when an empty DateInput receives focus or a click?
The DateInput has no configuration option for selecting the initial date segment. Use a DOM event handler with either the HtmlHelper or TagHelper.
Solution
The following example assumes that you have configured Telerik UI for ASP.NET MVC in your application.
- Configure an empty DateInput with the fixed
dd/MM/yyyyformat and explicit, nonempty segment messages. - After initialization, handle the input element's DOM
focusandclickevents. - Check both the widget value and the displayed mask to avoid changing populated or partially entered dates.
- Use
requestAnimationFrameto select the day after the component processes the interaction.
Choose one of the following declarations:
@(Html.Kendo().DateInput()
.Name("dateinput")
.Format("dd/MM/yyyy")
.Messages(messages => messages
.Day("dd")
.Month("MM")
.Year("yyyy")
)
)
Place this script after the chosen component declaration:
<script>
$(document).ready(function () {
var dateInput = $("#dateinput").data("kendoDateInput");
dateInput.element.on("focus click", function () {
var input = this;
if (dateInput.value() === null && input.value === "dd/MM/yyyy") {
requestAnimationFrame(function () {
if (document.activeElement === input && input.value === "dd/MM/yyyy") {
input.setSelectionRange(0, 2);
}
});
}
});
});
</script>
Tab into the empty input or click it. The day placeholder is selected, and typing replaces that segment. Populated dates and partially entered dates retain their normal editing behavior.
This example depends on the specified format and messages. If you change the date order, separators, or localized messages, update the empty-mask comparison and selection offsets.