JFOX
JFOX

Reputation: 245

Select and remove items from dojo.form.Multiselect

I have two sets of dojo.form.Multiselect boxes on a Wizard Dialog. They have the ability to transfer items between them like this example: Testing Multiselect from Widget. I also have a checkbox on the form and when a user clicks on it, I need to:

  1. Select all items in the first Multiselect box
  2. Move them to the right side select box via addSelected()
  3. Clear the first list of all items

The invsertSelection option doesn't work because if any items are selected at the time the checkbox is clicked, only the unselected items are selected and moved. I don't see a way in the API to do this nor a reliable method in the codesphere. Any suggestions?

Upvotes: 3

Views: 7322

Answers (2)

PEM
PEM

Reputation: 1978

Basically the addSelected does a dom query on the select to see which options are marked as selected :

query("option",this.containerNode).filter(function(n){
return n.selected; // Boolean
});

so you could basically select everything by doing :

query("option", myMultiSelect.containerNode).forEach(function(n){
    n.selected = true; // Boolean
});

then use addSelected... somethign like that should do the trick.

Upvotes: 0

JFOX
JFOX

Reputation: 245

Figured out a solution from looking at Dojo Docs and other code:

var selectItem1 = dijit.byId('firstSelectBox');

// Deselect all and invert to Select all
selectItem1.set("value",[]);
selectItem1.invertSelection();

//Move items to right box
var selectItem2 = dijit.byId('secondSelectBox');
selectItem2.addSelected(selectItem1);

Upvotes: 4

Related Questions