data("kendoAutoComplete") returns undefined

2 posts, 0 answers
  1. Brian Mains
    Brian Mains avatar
    485 posts
    Member since:
    Oct 2008

    Posted 09 Feb 2013 Link to this post


    I'm programmably initializing the auto complete plugin. Because I'm dynamically building the UI on the client, I'm using the client API, not the MVC server wrappers.  I have this function that does the initialization:

    function _initKendo(el) {
    $(el).attr("disabled", false).kendoAutoComplete({
    dataSource: _members,
    dataTextField: "Name",
    template: '<span data-id="${ data.UserKey }">${ data.Name }</span>',
    minLength: 2

    This approach works great.  If in this routine, I were to do:


    This works great here too.  _members has data as the selection of a member works.  The problem I am having is later on, when I want to extract information about the selected element, data("kendoAutoComplete") returns undefined.  So when the user submits a form, I block submission normally and send a JQuery AJAX request.  I need to grab the user key from the selected item,  To do this, I did:

    var auto = $(f).find(".k-autocomplete").data("kendoAutoComplete"); //f is the form that posted back, it has an autocomplete
    var item = auto.ul.find(".k-state-selected > span");

    This fails because it can't find the plugin, otherwise I believe it would work.  Why can't my code find the plugin using this approach?  I confirmed $(f).find("k-autocomplete") finds the correct element (the input)...

  2. Dimo
    Dimo avatar
    8404 posts

    Posted 12 Feb 2013 Link to this post

    Hi Brian,

    The AutoComplete client object is not attached to the widget wrapper (span.k-autocomplete), but to the element, from which it is created - el in in your case. This is the <input> element inside the <span>.

    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top