13

I'm using the Kendo UI ComboBoxes in cascade mode to build up a filter that I wish to apply.

How do I clear/reset the value of a Kendo UI ComboBox?

I've tried:

$("#comboBox").data("kendoComboBox").val('');
$("#comboBox").data("kendoComboBox").select('');
$("#comboBox").data("kendoComboBox").select(null);

all to no avail. The project is an MVC4 app using the Razor engine and the code is basically the same as the Kendo UI example.

Gaelan
  • 1,149
  • 11
  • 25
ciantrius
  • 683
  • 1
  • 6
  • 21

4 Answers4

19

If you want to use select the you need to provide the index of the option. Otherwise use text

$("#comboBox").data("kendoComboBox").text('');

Example: http://jsfiddle.net/OnaBai/4aHbH/

OnaBai
  • 40,767
  • 6
  • 96
  • 125
  • Thank you, exactly what I wanted. Thank you for taking the extra time to provide the example. – ciantrius Jun 28 '13 at 18:04
  • 1
    I have been running into bugginess in the Kendo ComboBox where it sometimes stops responding properly to ".value(text/value)" and ".select(1)" but it still responds to ".text('xx')". (perfectly normal api calls which normally work stop working) I set the value on the input before constructing the widget now which always works. – Curtis Yallop Aug 10 '13 at 00:00
  • This doesn't work.. try this.. select first value.. and click on reset. now, again select first value cascade box does not popup – Sagar Kulkarni Apr 30 '14 at 12:40
3

I had to create my custom clear function extending involved Kendo UI controls like the following:

kendo.ui.ComboBox.fn.clear = kendo.ui.AutoComplete.fn.clear = function () {
    if (!!this.text) {
        this.text("");
    }
    if (!!this.value) {
        this.value(null);
    }
    this._prev = this.oldIndex = this._old = this._last = undefined;
};

Then you can call $("mycontrol").data("kendoAutoComplete").clear(); to clear the control and have the change handler invoked when doing the following: select an item, clear and select again the previous item.

1

This also works:

$("#comboBox").data("kendoComboBox").value(null);
doglobster
  • 116
  • 8
1

I've found these options below seem to work to reset the kendo combo box. You can run $("#comboBox").data("kendoComboBox").select() after trying two below and you should see a value returned of -1, indicating its reset.

$("#comboBox").data("kendoComboBox").value('')
$('#comboBox').data().kendoComboBox.value('')
$("#comboBox").data("kendoComboBox").select(-1)
$('#comboBox').data().kendoComboBox.select(-1)
Matthew Ellison
  • 176
  • 3
  • 7