Unable to reference existing instance

3 posts, 0 answers
  1. Jane
    Jane avatar
    10 posts
    Member since:
    Oct 2016

    Posted 15 Nov 2016 Link to this post

    I have a dropdownlist defined as follows:

    <kendo:dropDownList name="module" dataTextField="domainValue" dataValueField="domainId">
            <kendo:dataSource data="${testModule}"></kendo:dataSource>
     </kendo:dropDownList>

     

    The html generated in the browser is as follows:

    <span class="k-widget k-dropdown k-header" style="" title="" unselectable="on" role="listbox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-owns="module_listbox" aria-disabled="false" aria-busy="false" aria-activedescendant="b5f28c08-1663-4dfc-bebe-a03898405acf">
    <span class="k-dropdown-wrap k-state-default" unselectable="on">
    <span class="k-input" unselectable="on">Library</span>
    <span class="k-select" aria-label="select" unselectable="on">
    </span>
    <input id="module" name="module" data-role="dropdownlist" style="display: none;">
    </span>
    <script>
    jQuery(function(){jQuery("#module").kendoDropDownList({"dataSource":{"data":[{"domainId":17,"domainValue":"Library","domainCode":"TMOD"},{"domainId":18,"domainValue":"Regular","domainCode":"TMOD"},{"domainId":19,"domainValue":"Advanced","domainCode":"TMOD"},{"domainId":20,"domainValue":"Unknown","domainCode":"TMOD"}]},"dataValueField":"domainId","dataTextField":"domainValue"});})
    </script>

     

    Then in a $(document).ready function I have the following:

    var dropdownlist = $('#module').data("kendoDropDownList");
    dropdownlist.select(function(dataItem) {
           return dataItem.value === "Regular";
    });

     

    The second line throws a javascript error because the variable dropdownlist is not defined. 

    Note I have 3 other dropdownlists defined on the page, all with different names, obviously, and get the same error.

    Please tell me where I'm going wrong.  Thank you.
  2. Stefan
    Admin
    Stefan avatar
    579 posts

    Posted 15 Nov 2016 Link to this post

    Hello Jane,

    The example looks good.

    If the reference is indeed correctly placed in the $(document).ready(function() {}) function, then the error should not occurs.

    Please send us an isolated runnable example, so we can investigate locally if there is any additional custom code which may be causing this error.

    Also, before using the select function please log the dropdownlist variable to check if the instance of the widget is successfully retrieved.

    I will be expecting the example to continue the investigation.

    Regards,
    Stefan
    Telerik by Progress
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Jane
    Jane avatar
    10 posts
    Member since:
    Oct 2016

    Posted 15 Nov 2016 in reply to Stefan Link to this post

    Thanks Stefan, it was user error.  There was a problem with my program flow and I was refreshing the page unnecessarily which caused the dropdown to not be available at  that point.  Thank you for your prompt reply. :)
Back to Top