0

I have 2 multi-select picklists and I want to: 1. Add all the values selected in Picklist1 to Picklist2 2. Remove the selected values from Picklist1 after they are added to Picklist2

While, I am able to achieve the 1st requirement. How to achieve the 2nd requirement.

  • What did you try so far? – Reshma Mar 20 '17 at 9:39
  • I tried using selectedIndex and Picklist2[options] as used in javascript for picklists. But, these values come out to be "undefined" – Komal Narsinghani Mar 20 '17 at 9:40
  • Any idea how can I get the indices of selected elements of a multi-select picklist? – Komal Narsinghani Mar 20 '17 at 9:45
  • Can you post the corresponding code also? – Reshma Mar 20 '17 at 9:47
1

Ok, so assuming you have just completed step 1, you have a large list in picklist 1 and a smaller list in picklist two.

I'm also assuming that you are using databinding in lightning are are not directly manipulating the DOM

Given these conditions, run your first list through this function. It will remove any dupe values already in the second list:

xorSourceItems : function(source,dest) {
  var itemsToReturn = [];
  source.forEach(function(sourceItem, sourceIndex) {
    var match = false;
    dest.forEach(function(destItem, destIndex) {
      if (destItem.value == sourceItem.value) {
        match = true;
      }
    });
    if (!match){
        itemsToReturn.push(sourceItem)
    }
  });
  return itemsToReturn;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.