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

Unable to reference existing instance

2 Answers 413 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Jane
Top achievements
Rank 1
Jane asked on 15 Nov 2016, 06:47 AM

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 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 15 Nov 2016, 12:11 PM
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!
 
0
Jane
Top achievements
Rank 1
answered on 16 Nov 2016, 05:20 AM
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. :)
Tags
DropDownList
Asked by
Jane
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Jane
Top achievements
Rank 1
Share this question
or