Concatenate labels of selected values in multiselect enabled dropdown

Hi,

I’m using a dropdown with multiselect enabled to allow users to select multiple options on it. How do I get all labels of selected values and concatenate with ‘/’ separation between each item. I need to write these concatenated labels to SQL database.

I managed to do it this way and it works.

Created a custom label as selectedlabel with expression binding on {this.props.value} and a script transform as follow:

  x = ""
  mylist = self.props.value
  myoptions = self.props.options
  selLabels = []

  for i in mylist:
    for j in range(len(self.props.options)):
		if self.props.options[j].value == i:
			selLabels.append(self.props.options[j].label)
    x = '/'.join(selLabels) 
   return x

Please let me know if there is anyother simplest form to obtain this result.

There’s no ‘better’ way to do it than to loop through the possible options and compare them with the selected values, no. You can make the script a little cleaner using a list comprehension; create a custom property with a property binding to self.props.value, and then add a script transform:
return "/".join(o.label for v in value for o in self.props.options if o.value == v)
But it’s the same script as what you’ve written.