Search code examples
selectionkendo-asp.net-mvconfocus

Kendo IntegerTextBoxFor select all numbers on focus


I've seen many great posts on using jQuery to select all text for regular input boxes...

$("input[type='text']").on("click", function () {
   $(this).select();
});

The above works great for

  @Html.TextBoxFor(...etc

But does not work for:

@Html.Kendo().IntegerTextBoxFor(...

and

 @Html.Kendo().CurrencyTextBoxFor(...

I tried to see if there's a focus event in Kendo I could attach to so I could select all, but no joy.

The funny thing is, the rendered input control does have type="text" so the jQuery input[type='text'] SHOULD work...but doesn't.

Anyone find something that works for these guys?


Solution

  • I'm not sure if this will exactly work, but might get you started.

    To do [much] with the Kendo rendered controls, you have to do something like:

    var control = $('#my-control').data('kendoNumericTextBox');
    

    Then you can call methods/properties on control.

    So, in this case, something like this might work:

    var control = $('#my-control').data('kendoNumericTextBox');
    control.focus();
    

    The API documentation for the NumericTextBox can be found here http://docs.telerik.com/kendo-ui/api/web/numerictextbox#methods-focus