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

How to set multiple items in a multi selection combobox in javascript

1 Answer 97 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Tomasz
Top achievements
Rank 1
Tomasz asked on 17 Nov 2015, 09:30 AM
Hello.

I have a multiselect combobox with checkeboxes. Let assume that variable "options" has value "Building 1, Building 2". My combobox has items "Building 1", "Building 2", "Building 3". I want to by using JS select and check those two values. This code check Building 1 and Building 2, but only Building 2 is really selected.


function setValuesInCombobox(options) {
    var controler =$find(getClientIdById(cboBuildingControlName));   
    controler.set_value(options);
    controler.set_text(options);
    var allChoicesFromCbo = controler.get_items()._array; 
    var selectedOptions =  options.split(",");
 
    for(i = 0; i < selectedOptions.length; i++) {
      var building = selectedOptions[i].trim();
      for(j = 0; j < allChoicesFromCbo.length; j++) {       
        var nameOfBuildingInCbo = allChoicesFromCbo[j]._properties._data.value;
        if( nameOfBuildingInCbo == building) {
          allChoicesFromCbo[j]._setChecked(true);
          allChoicesFromCbo[j].select();
        }
      }
    }

1 Answer, 1 is accepted

Sort by
0
Magdalena
Telerik team
answered on 18 Nov 2015, 07:43 AM
Hi Tomasz,

As there are missing resources, we have remove the if statement and the sample works properly - all items all checked. You can check it by the get_checked() method. We are sending you the sample in the attachment. Could you please modify the sample so the issue will be reproduced?

Regards,
Magdalena
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ComboBox
Asked by
Tomasz
Top achievements
Rank 1
Answers by
Magdalena
Telerik team
Share this question
or