How to empty combobox?

5 posts, 1 answers
  1. Sergi
    Sergi avatar
    34 posts
    Member since:
    Sep 2007

    Posted 17 Jun 2013 Link to this post

    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.
  2. Answer
    Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2564 posts

    Posted 18 Jun 2013 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Sergi
    Sergi avatar
    34 posts
    Member since:
    Sep 2007

    Posted 18 Jun 2013 Link to this post

    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.
  5. Sharon
    Sharon avatar
    9 posts
    Member since:
    Dec 2013

    Posted 29 Apr 2014 in reply to Kiril Nikolov Link to this post

    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? 
  6. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2564 posts

    Posted 29 Apr 2014 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready