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

[Solved] Can we clear Multiple comboboxes plus how to add default first value

3 Answers 79 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Angelo
Top achievements
Rank 1
Angelo asked on 25 Oct 2011, 06:01 AM
Hi,
 
   We're changing from the normal MVC helpers to telerik MVC and I have to question:
   1. How do I add a 'default' empty first value (like Please Select) - in the normal HTML helper we did it via via :
       @Html.DropDownListFor(model => model.FieldNameHere, (SelectList)ViewData["FieldList"], "--- Please select a value ---", new { Id = "Selection", @class = "classname" })

      I can't find the corresponding one in the Telerik documentation.

   2. Also, can I 'reset'/'clear the values of several comboboxes. In our page, we have 5 cascading comboboxes and when we select the new values for the upper comboboxes, the ones below needs to be cleared as the selection will be reset. Example, select new value for first combobox, we need to clear the second to fifth combox (and refresh second combo with new data if applicable). If the normal Html.DropDownListFor, we just use one jQuery like this :
      $('#Selection2,#Selection3,#Selection4,#Selection5').empty();

      I tried $('#Selection2,#Selection3,#Selection4,#Selection5').data('tComboBox').close()  but I get an error (not sure if this is the correct command).

    Thanks.

3 Answers, 1 is accepted

Sort by
0
Angelo
Top achievements
Rank 1
answered on 26 Oct 2011, 12:45 AM
 For question 1.) Seems the answer is a no. So just ignore that question.
 For question 2.) I used the wrong command. I changed it to :

        var dropdownsToReset = $('#Selection2,#Selection3,#Selection4,#Selection5').data('tComboBox');
        if (dropdownsToReset != null) {
            dropdownsToReset.dataBind();
        }

 But the problem I have now is that all the previously selected 'Text' is still retained in some of the comboboxes. Strange thing is that if I click anywhere on a page, they disappear. But is there a way to make them 'disappear' immediately?
0
Georgi Krustev
Telerik team
answered on 26 Oct 2011, 02:12 PM
Hello Angelo,

 
This code snippet will return only one ComboBox object, not all:

$('#Selection2,#Selection3,#Selection4,#Selection5').data('tComboBox');

In order to achieve your goal you will need to use .each() like so:
var dropdownsToReset = $('#Selection2,#Selection3,#Selection4,#Selection5');
 
dropdownsToResest.each(function() {
    var ddl = $(this).data('tComboBox');
    if (ddl != null) {
         ddl.dataBind();
     }
});
Regards,
Georgi Krustev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Angelo
Top achievements
Rank 1
answered on 26 Oct 2011, 11:35 PM
Works great. Thanks Georgi.
Tags
ComboBox
Asked by
Angelo
Top achievements
Rank 1
Answers by
Angelo
Top achievements
Rank 1
Georgi Krustev
Telerik team
Share this question
or