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

How to empty combobox?

4 Answers 2059 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Sergi
Top achievements
Rank 1
Sergi asked on 17 Jun 2013, 02:00 PM
I have a combobox bind with ajax to a server method, but I need to empty it when the user selects some options on the UI.

How can I empty the combobox?

Thanks in advance.

4 Answers, 1 is accepted

Sort by
0
Accepted
Kiril Nikolov
Telerik team
answered on 18 Jun 2013, 08:35 AM
Hello Sergi,

The items that you have in your combobox depend on the data passed to the dataSource field when you initialize it. In order to clear the contents of your combobox I would suggest two ways to do it:

  1. You can use the setDataSource() method without parameters so you will set empty value to the dataSource field to clear the combobox:

    $("#comboBox").data("kendoComboBox").setDataSource();

    In this case in order to bind your data again you will need to save the data that you get from your AJAX request to a variable, so you can  bind it when its needed again.

  2. Another way to achieve your goal is to clear out the value of the combobox and then disable it. This way nothing will be shown in the combobox and it will be disabled, so the users will not be able to click on it.

    Here is an example:

    var combobox = $("#comboBox").data("kendoComboBox");
    combobox.value();
    combobox.enable(false);

Regards,
Kiril
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Sergi
Top achievements
Rank 1
answered on 18 Jun 2013, 08:40 AM
Thanks, I will clear the value and disable the combobox as you propose, I don't feel comfortable having to  change the datasource back and forth.
0
Sharon
Top achievements
Rank 1
Iron
answered on 29 Apr 2014, 12:47 PM
I used your sugesstion of how to empty combo, but when I initilized the combo again (insert again url, etc) it didn't work.

Do you have simpler way? 
0
Kiril Nikolov
Telerik team
answered on 29 Apr 2014, 01:01 PM
Hi Sharon,

Can you please extract a runnable sample in a Kendo UI Dojo where you can exactly demonstrate what you are doing, so we can reproduce the issue and advise you further?

You can also start your own thread, so we can easily track down all the issues our users have.

Thank you in advance for your cooperation.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
ComboBox
Asked by
Sergi
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Sergi
Top achievements
Rank 1
Sharon
Top achievements
Rank 1
Iron
Share this question
or