jakezatecky / react-dual-listbox

A feature-rich dual listbox for React.
https://jakezatecky.github.io/react-dual-listbox/
MIT License
110 stars 59 forks source link

Property selected #105

Closed oscarcornejo closed 4 years ago

oscarcornejo commented 4 years ago

Hi, any option to get the label content and not the value with the selected property? I need to insert the value I get in a textarea input with the data that happened to the second column, but by doing this I only get the value content:

const options = [
     {value: 'one', label: 'Option One'},
     {value: 'two', label: 'Option Two'},
]

current output: ['one', 'two'];
I need: ['Option One', 'Option Two'];

I would appreciate the help. Regards!

jakezatecky commented 4 years ago

Hello, that is not supported. You have a couple options to get the labels from the selected values passed in the onChange function:

  1. Set simpleValue={false} and then map your selected options to labels:
// When <CheckboxTree simpleValue={false} />
const labels = this.state.selected.map(option => option.label);
  1. Use the selected values to determine the labels:
// When using default properties
// Construct value/label mapping
const labelMap = {};
options.forEach((option) => {
  labelMap[option.value] = option.label;
});
// Convert selected values to labels
const labels = this.state.selected.map(value => labelMap[value]);
jakezatecky commented 4 years ago

Closing due to lack of activity. Please reopen if you still have issues.