Set Focus

11 posts, 1 answers
  1. Micha
    Micha avatar
    14 posts
    Member since:
    Oct 2011

    Posted 20 Oct 2011 Link to this post

    How can i set the focus on a combobox? $('#combo').focus(); doesn't work!
  2. Dimo
    Admin
    Dimo avatar
    8330 posts

    Posted 20 Oct 2011 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Micha
    Micha avatar
    14 posts
    Member since:
    Oct 2011

    Posted 20 Oct 2011 Link to this post

    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.... 
  5. Dimo
    Admin
    Dimo avatar
    8330 posts

    Posted 20 Oct 2011 Link to this post

    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!
  6. Micha
    Micha avatar
    14 posts
    Member since:
    Oct 2011

    Posted 20 Oct 2011 Link to this post

    $('#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). 

  7. Answer
    Dimo
    Admin
    Dimo avatar
    8330 posts

    Posted 20 Oct 2011 Link to this post

    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!
  8. Micha
    Micha avatar
    14 posts
    Member since:
    Oct 2011

    Posted 20 Oct 2011 Link to this post

    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 ;)
  9. Dimo
    Admin
    Dimo avatar
    8330 posts

    Posted 20 Oct 2011 Link to this post

    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!
  10. Dan
    Dan avatar
    9 posts
    Member since:
    Sep 2012

    Posted 25 Sep 2012 Link to this post

    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
  11. Rrvijay
    Rrvijay avatar
    1 posts
    Member since:
    Mar 2012

    Posted 24 Jan 2013 Link to this post

    i use this code for combo box  but border not work $("#contact").focus(); wt problem
  12. beauXjames
    beauXjames avatar
    20 posts
    Member since:
    Aug 2012

    Posted 15 Feb 2013 Link to this post

    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.
Back to Top
Kendo UI is VS 2017 Ready