Adam Mrozek
Adam Mrozek

Reputation: 1480

Data stored in select option is missing after create kendo combobox

I have a problem with missing data attributes in option after initialize kendo ui combobox.

My select look like this:

<select id="users">
    <option value="1" data-message="OK1">User 1</option>
    <option value="2" data-message="OK2">User 2</option>
</select>

now I create a kendo combobox based on this control:

$("#users").kendoComboBox({
    change: function() {
        alert($("#users option:selected").attr("data-message"));
    }
});

and the result is "undefined".

The 'data-message' stored value is missing. Is there any way to store this information in combobox?

I've found similar question here: https://stackoverflow.com/questions/26769175/delete-stored-jquery-data-data-element-option-after-creating-a-kendo-combobox but still no answer.

Here is telerik dojo to test the code above: http://dojo.telerik.com/eyORO

Please help

Regards

Upvotes: 1

Views: 425

Answers (1)

Lars H&#246;ppner
Lars H&#246;ppner

Reputation: 18402

That's actually a bit unusual since other widgets like the treeview keep their data attributes when created like that; anyway, your best option is to use a data source instead:

<input id="users" />

$("#users").kendoComboBox({
    dataTextField: "text",
    dataValueField: "value",
    dataSource: [
        { text: "User 1", value: "1", message: "OK1" },
        { text: "User 2", value: "2", message: "OK2"  }
    ],
    change: function() {
        console.log(this.dataItem().message);
    }
});

Upvotes: 0

Related Questions