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

2 posts, 0 answers
  1. Lee Saunders
    Lee Saunders avatar
    20 posts
    Member since:
    Jul 2009

    Posted 19 Mar 2014 Link to this post

    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>

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

    but now that I've converted the select to a dropdownlist, the jquery calls are failing to return the data.
  2. Georgi Krustev
    Georgi Krustev avatar
    3725 posts

    Posted 20 Mar 2014 Link to this post

    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.

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