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

How to access "DATA-" attributes in a option after converting select to a dropdownlist

1 Answer 565 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Lee Saunders
Top achievements
Rank 1
Lee Saunders asked on 19 Mar 2014, 08:52 PM
How do I access "DATA-" attributes in a option after converting the select to a kendo dropdownlist?

Here is an example of my select:
<select id='connect-search-results'>
<option data-text='Text-One' data-id='Data-One' data-url='\\One'>One</option>
<option data-text='Text-Two' data-id='Data-Two' data-url='\\Two'>Two</option>
</select>

I was using:
   var $option = $('#connect-search-results option:selected');
     
   if ($option.length > 0) {
      var id = $option.data('id');
      var url = $option.data('url');
      var text = $option.data('text');  
      ...
   }

but now that I've converted the select to a dropdownlist, the jquery calls are failing to return the data.

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 20 Mar 2014, 11:39 AM
Hello Lee,

The DropDownList widget is designed to infer the data from the SELECT options and to create data items persisted in the widget's data source.  Currently, data attributes are ignored when widget infers data from the SELECT options. Note also, that widget recreates the option elements of the widget on init even when the element is defined declaratively. You can overcome this behavior if you define the data source of the widget instead of using a SELECT element with options. Check this demo for more information.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
DropDownList
Asked by
Lee Saunders
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or