2

Looking at the documentation here, it was pretty straightforward to get the 'values' of selected options in a lightning:dualListbox. But how can I get the corresponding labels without executing another SOQL?

CONTROLLER JS:

({
    onChange: function (cmp, event) {
    // This returns all selected 'values'
    var selectedOptionValue = event.getParam("value"); // This works
    var selectedOptionLabel = event.getParam("label"); // How to accomplish this?
    }
})

I tried looking at the selectedOptions and event in console, but they all seem to carry just the values...?

var selectedOptions = component.get("v.selectedOptions");
console.log('-------> selectedOptions JSON = ' + JSON.stringify(selectedOptions, null, 2)); 

var selectedOptionsList = event.getParam("value");
console.log('-------> selectedOptionsList JSON = ' + JSON.stringify(selectedOptionsList, null, 2)); 

console.log('-------> event JSON = ' + JSON.stringify(event, null, 2)); 

enter image description here

2
  • 1
    There's no point in blanking out ID values; they're completely useless outside of your org.
    – sfdcfox
    Commented May 30, 2018 at 17:00
  • We are a super secure org so doing everything I can to stay out of trouble :-) Commented May 30, 2018 at 17:02

1 Answer 1

3

Just filter the original option list, and optionally map them:

var values = event.getParam("value");
var labels = component.get("v.listOptions")
      .filter(option => values.indexOf(option.value) > -1)
      .map(option => option.label);

If you're not storing the values anywhere, but setting them directly, you can still interrogate the dualListbox for its options:

var values = event.getParam("value");
var labels = component.find("myDualListbox").get("v.options")
      .filter(option => values.indexOf(option.value) > -1)
      .map(option => option.label);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .