Simmy Dhanda
Simmy Dhanda

Reputation: 149

Kendo ComboBox - How to select option based on its text() rather than value()?

I am really struggling to select an option from my combo box based on the text rather than value. I have a combo box which has a datasource attached to it which are countries. These countries are stored in the database. I want the default country to be "United Kingdom". At the moment I am doing the following:

combobox.select(combobox.text("United Kingdom"));

However, this only shows the text and doesn't actually select it because the select function does not trigger. Any help with this?? I want the value to be applied. I have an alert in the select function which is not appearing.

Upvotes: 3

Views: 4379

Answers (2)

Satya Ranjan Sahoo
Satya Ranjan Sahoo

Reputation: 1086

Selecting kendo comboBox value explicitly from javascript don't trigger the "Select" event.

In order achieve that you have to trigger the "Select" event after setting the required value. e.g.

 var myComboBox = $('#comboBoxId').data('kendoComboBox');
 myComboBox.text("United Kingdom");
 myComboBox.trigger("select");

Hope this will solve your purpose. Also check here.

Upvotes: 3

George K
George K

Reputation: 1763

Use the select method of the widget and pass a predicate

combobox.select(function(dataItem) {
    return dataItem.text === "Apples"; //note that 'text' === dataTextField
});

Here is a runnable demo demonstrating this approach.

Upvotes: 4

Related Questions