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

Set Focus

10 Answers 1733 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Micha
Top achievements
Rank 1
Micha asked on 20 Oct 2011, 08:23 AM
How can i set the focus on a combobox? $('#combo').focus(); doesn't work!

10 Answers, 1 is accepted

Sort by
1
Dimo
Telerik team
answered on 20 Oct 2011, 08:43 AM
Hello Micha,

If #combo is the element to which the ComboBox object is attached, then you can use:

$("#combo").data("kendoComboBox").input.focus();

All the best,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Micha
Top achievements
Rank 1
answered on 20 Oct 2011, 08:48 AM
Hmm a more generic version would be nice... because we set the field name programaticaly in the application and the focus script is registrated on the page when its rendered. So I have no idea what kind of field I have.... 
0
Dimo
Telerik team
answered on 20 Oct 2011, 11:44 AM
Hello Micha,

Well, this:

$("#combo").data("kendoComboBox").input.focus();

is as generic as this, that you tried to use:

$('#combo').focus();

Generally, you should have a reference to the ComboBox widget client object and then call

clientObject.input.focus();

The easiest way to obtain a reference to a widget is via the element to which the widget is attached. If you have some more specific requirements, please explain in more details.

All the best,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Micha
Top achievements
Rank 1
answered on 20 Oct 2011, 12:17 PM
$('#combo').focus();


is more generic, because I can use it with any input field on a form. 

clientObject.input.focus();


Here I need to know that I have to set the focus on the Combofield (or Datepicker or dropdown or.....) 

I would like that you're controls handle focus themself, if the behaviour must be different then the default behaviour (e.g. because the field is hidden and replaced by another field). 

0
Accepted
Dimo
Telerik team
answered on 20 Oct 2011, 12:55 PM
Hi Micha,

Now I understand what you mean. We have implemented the described behavior and it will be supported. You can add the following code in kendo.combobox.js:

init: function(element, options) {
            var that = this;

            options = $.isArray(options) ? { dataSource: options } : options;

            Select.fn.init.call(that, element, options);

            options = that.options;
            element = that.element.focus(function() {
                that.input.focus();
            });


.........


Note that you can only focus the #combo element via jQuery. Doing the same via document.getElementById("combo").focus() will cause a Javascript error in IE, because the input element to which the ComboBox object is attached has a display:none style.

Regards,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Micha
Top achievements
Rank 1
answered on 20 Oct 2011, 01:14 PM
great, thakn you! 

Would it be possible to implement it for all controls (like DropDown)?  

... hmm will waite until next release... quite annoying to apply such changes to minified files ;)
0
Dimo
Telerik team
answered on 20 Oct 2011, 01:45 PM
Hi Micha,

Yes, the DropDownList will support such focusing as well. The DatePicker and NumericTextBox will support it with no need for additional Javascript, because the textbox element remains visible after widget initialization.

Greetings,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Dan
Top achievements
Rank 1
answered on 25 Sep 2012, 03:34 PM
This is not working for me - I put it in a document.ready handler on the form, and have validated that my selector is correct.  When I try to access .data("kendoComboBox") it returns undefined.  I have noticed this in other situations as well.  When can .data be used, and when will it be undefined?  Also - is there a reason there is no Init or Load function exposed for the combobox?  It seems like that would be a good place to call a function to set focus.

Thanks, DanO
0
Rrvijay
Top achievements
Rank 1
answered on 24 Jan 2013, 11:13 AM
i use this code for combo box  but border not work $("#contact").focus(); wt problem
0
beauXjames
Top achievements
Rank 2
answered on 15 Feb 2013, 10:32 PM
try $("#contact:last-child").focus()

this pulls the <select> element out of the thorns...

One of the issues I run into with certain IE versions is that the focus will remove the selection of a KendoDropDown if and when I tab out of the control. Having a beast of a time with these subtleties myself.
Tags
ComboBox
Asked by
Micha
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Micha
Top achievements
Rank 1
Dan
Top achievements
Rank 1
Rrvijay
Top achievements
Rank 1
beauXjames
Top achievements
Rank 2
Share this question
or