This is a migrated thread and some comments may be shown as answers.

Select text on focus

21 Answers 2256 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
EDWARD
Top achievements
Rank 1
EDWARD asked on 09 Jan 2012, 11:08 AM
How can I select the textbox's contents when it receives the focus.  Ordinarily, I would call select() within jQuery's focus event handler.  However, this does not work with the numeric textbox.  I presume this is because the input that ultimately receives focus has style display:none when the page is loaded.

21 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 10 Jan 2012, 02:04 PM
Hello Edward,

 
You will need to use setTimeout to achieve your goal. Check this jsFiddle demo.

All the best,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
EDWARD
Top achievements
Rank 1
answered on 12 Jan 2012, 08:06 PM
Thanks.

I used this in a more general approach to the problem:

$('.k-input').on('focus', function () {
        var input = $(this);
        setTimeout(function () { input.select(); });
    });
0
Fernando Nogues
Top achievements
Rank 1
answered on 11 Apr 2012, 01:00 AM
This is working great for me, thanks EDWARD.

In my opinion this should be the default behavior as it is for other regular inputs.
0
Mike
Top achievements
Rank 1
answered on 16 Oct 2012, 03:46 PM
The standard behavior of selecting all text when tabbing into an input should work with the NumericTextBox both inside and outside of a Kendo Grid, and should be built into Kendo.

We have created a UserVoice entry for this - go vote on it if you agree!
0
z
Top achievements
Rank 1
answered on 19 Feb 2013, 04:44 PM
if you want to use this behavior of selecting all text in NumericTextBox inside a Kendo Grid, create a editor for the column:
  { field: "Budget", title: "Budget",  editor: editNumberWithoutSpinners }

    function editNumberWithoutSpinners(container, options) {
                var fld = $('<input data-text-field="' + options.field + '" ' +
            'data-value-field="' + options.field + '" ' +
            'data-bind="value:' + options.field + '" ' +
            'data-format="' + options.format + '"  />');
                fld.focus(function () {
                    this.select();
                });
                fld.appendTo(container)
                fld.kendoNumericTextBox({
                    spinners: false
                });
            }

0
Robert
Top achievements
Rank 1
answered on 02 Apr 2013, 07:57 PM
Attempting to select text on focus, but in a grid field. Here's a jsbin: http://jsbin.com/ekegas/2/edit
In this simple grid, trying to set the 'name' column text when in focus, but its not working, even with the timeout.
What am I missing?
0
Alexander Valchev
Telerik team
answered on 05 Apr 2013, 12:23 PM
Hi Robert,

In your case the combo is bound to remote data, this means that the widget will populate after data is received. You should bind to the dataBound event of the combo and select the text of its input element.
editor:function categoryDropDownEditor(container, options) {
   $('<input required data-text-field="CategoryName" data-value-field="CategoryID" data-bind="value:' + options.field + '"/>')
   .appendTo(container)
   .kendoComboBox({
     autoBind: false,
     dataSource: {
       type: "odata",
       transport: {
       }
     },
     dataBound: function() {
       var combo = this;
       setTimeout(function() {
         combo.input.select();
       }, 0);
     }
   });
}

It is also required to wrap the select logic inside a time out, because the text is actually set after dataBound triggers.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Shea
Top achievements
Rank 1
answered on 22 Apr 2013, 06:34 PM
I used z's suggestion to fix this for myself. But this really should be the default behaviour. 

A very common use case if for users to tab between fields, then tab to the next field. Especially when these editors are part of a grid (which is also common). With this bug users must tab into the field, backspace the existing characters (or in IE del them, weird that they are different). Totally destroying the rapid input use case.

Here's to hoping this gets fixed in 2013.2.

~S
0
Atlas
Top achievements
Rank 1
answered on 30 May 2013, 01:42 AM
I agree, this should be the default behavior. In addition, it would be nice to have a configuration setting for it so that you can easily do what you want. The RadNumericTextbox works this way.
0
Atanas Korchev
Telerik team
answered on 30 May 2013, 05:55 AM
Hello,

 We cannot modify the default behavior because it would be a breaking change. We recommend opening a new feature request in our feedback portal.

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Daniel
Top achievements
Rank 1
answered on 14 Aug 2014, 03:54 PM
Hi,

one year later and the same odd (annoying) behavior.
This behavior makes end-users crazy!


Please vote up for this:
http://kendoui-feedback.telerik.com/forums/127393-telerik-kendo-ui-feedback/suggestions/3264987-automatically-select-all-when-tabbing-into-the-num


Regards,
Daniel

PS: Such a behavior doesn't have to be in such good UI control set.
0
Allan
Top achievements
Rank 1
answered on 31 Mar 2017, 08:01 AM
And still we wait...  is it worth adding votes to feedback forums, it doesn't seem to make any difference.  I thought we would see the behaviour corrected when they introduce brand new .Net Core controls...  but alas no.  Wouldn't have been a breaking change on new controls... which was the previous excuse.
0
Boyan Dimitrov
Telerik team
answered on 05 Apr 2017, 06:31 AM

Hello Allan,

In general our wrappers render the HTML and JavaScript needed to initialize a Kendo UI widget. The widget options propagate to the client-side via the widget initialization script. The Telerik UI for ASP.NET Core does not make any difference and works in the same way. 

Given this in order to change the behavior in .Net Core controls we should eventually change it in the Kendo UI NumericTextBox for JavaScript. Definitely this will be rather a breaking change with our current behavior and this can cause different behavior in existing projects of many our customers. We are trying to avoid introducing breaking changes so we do our best to find a workaround/solution to achieve this behavior  without modifying the source code of our widgets (in cases when such modification will introduce a breaking change with the current behavior). Currently my suggestion is to go with the solution provided in the http://docs.telerik.com/kendo-ui/controls/editors/numerictextbox/how-to/select-all-on-focus how-to article. 

 

Regards,
Boyan Dimitrov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Anton Mironov
Telerik team
answered on 14 Sep 2020, 06:07 PM
Hi Colleagues,

I would like to share with you that as of Kendo UI version 2020.2.617, our team has added the "selectOnFocus" property covering the pointed requirements in this thread.  For your future web development, feel free to utilize this implementation shown here:
<input id="numerictextbox" />
<script>
$("#numerictextbox").kendoNumericTextBox({
    selectOnFocus: true
});
</script>
If you have any questions about the new functionality don't hesitate to contact our team.

Kind Regards,
Anton Mironov
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

0
jason2k
Top achievements
Rank 1
answered on 06 Nov 2020, 06:35 PM
[quote]Anton Mironov said:Hi Colleagues,

I would like to share with you that as of Kendo UI version 2020.2.617, our team has added the "selectOnFocus" property covering the pointed requirements in this thread.  For your future web development, feel free to utilize this implementation shown here:
<input id="numerictextbox" />
<script>
$("#numerictextbox").kendoNumericTextBox({
    selectOnFocus: true
});
</script>
If you have any questions about the new functionality don't hesitate to contact our team.

Kind Regards,
Anton Mironov
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

[/quote]

 

This does not work on its declarative init counterpart though:

<input type="number" data-role="numerictextbox" data-select-on-focus="true" />
0
Anton Mironov
Telerik team
answered on 09 Nov 2020, 09:11 AM

Hello Jason,

Try the following implementation for the Kendo UI NumericTextBox:

<kendo-numerictextbox name="numeric" select-on-focus="true"></kendo-numerictextbox>
Using the latest version of the Kendo UI should work out of the box for the "selectOnFocus".

I hope this information helps.

 

Best Regards,
Anton Mironov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Andy
Top achievements
Rank 1
answered on 23 Dec 2020, 11:37 AM

Hi Anton

This doesn't appear to work on a numeric textbox within a grid.  I have updated the EditorTemplates to include this, but it still appears to make no difference.  Am I missing something?

 

Thanks

 

Andy

0
Tsvetomir
Telerik team
answered on 28 Dec 2020, 06:59 AM

Hello,

Attached to my response is a sample project using the latest version of the suite. It utilizes the Kendo UI NumericTextBox as an editor for a column. It appears to be working as expected. Can you confirm this on your side?

It would be very helpful if you could share the relevant code snippets for the grid and editor templates. As well as, the suite of Kendo UI that you are using.

 

Kind regards,
Tsvetomir
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Andy
Top achievements
Rank 1
answered on 05 Jan 2021, 11:52 AM

Hi Tsvetomir

Sorry for the delay, the email went to my junk.   Will review today and get back to you.

 

Andy

0
Andy
Top achievements
Rank 1
answered on 05 Jan 2021, 01:53 PM

Hi Tsvetomir

I am using a new version of the Kendo UI  (Version 2020.3.1118), the version in your sample is 2020.2.617

The supplied sample you shared doesn't actually apply a select on focus to the Order ID field, which highlights my issue.

When the numeric textbox is used as an editor for the grid, the select on focus is not applied, and tabbing to the field doesn't highlight the number, but sets focus to the end of the value (i.e. after the value).

My understanding of the automatic templates used for grid editing is that it uses the templates in the shared\editortemplates directory, so altering these will alter how the controls are displayed?

My issue is that when editing a grid in-line, I need the select on focus set, so a user can tab between fields editing / adding values and the previous value is highlighted.

 

Andy

 

 

 

 

0
Tsvetomir
Telerik team
answered on 07 Jan 2021, 02:12 PM

Hi Andy,

I apologize for the misinformation. I have attached the sample project that I used as a base rather than the modified version. I am reattaching the correct one to my response.

The editor templates located within the EditorTemplates folder of the project are data type-specific. The attached sample has different editors for the OrderID and the Freight due to the fact that the latter one is of decimal data type whereas OrderID is of type integer.

You could examine the "Decimal.cshtml" file that has the select-on-focus property enabled.

 

Best regards,
Tsvetomir
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
NumericTextBox
Asked by
EDWARD
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
EDWARD
Top achievements
Rank 1
Fernando Nogues
Top achievements
Rank 1
Mike
Top achievements
Rank 1
z
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Alexander Valchev
Telerik team
Shea
Top achievements
Rank 1
Atlas
Top achievements
Rank 1
Atanas Korchev
Telerik team
Daniel
Top achievements
Rank 1
Allan
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Anton Mironov
Telerik team
jason2k
Top achievements
Rank 1
Andy
Top achievements
Rank 1
Tsvetomir
Telerik team
Share this question
or