Hi,
I have a dropdown component and I'd like to get the selected text.
The problem is that my dropdown values are not 0,1,2,3 etc. I have random values, like the first row has the value1651, second row 1700 (just as examples), etc.
How can I get the selected text? Thanks.
The props.value
will always hold the selected value(s), are you wanting the selected Label(s)?
Is the dropdown set for multiselection?
Hi,
Yes, I can see the selected values using "props.value". But I'd like to get the selected label(s).
It's not set for multiselection.
Thanks.
How is your dropdown populated ? SQL query or manually entered in the props etc?
Something along these lines should do the trick, assuming that your options are a list of objects. If they are a dataset then it will need to be modified slightly.
for option in self.props.options:
if option.value == self.props.value:
self.custom.selectedLabel = option.label
return
With a dataset you could potentially use an expression binding with the lookup()
expression function.
It is populated by a query, it's not populated manually.
If your not interested in what the value is and only want the label you can modify your SQL so the label and value match, you can then use the value prop.
Select name as 'value', name as 'label'
Another method..
On the dropdown create a custom property called displayvalue
.
On the dropdown value prop, right click and add a change script.
data = self.props.options
for row in range(data.getRowCount()):
if (data.getValueAt(row, "value") == self.props.value):
self.custom.displayvalue = data.getValueAt(row, "label")
break
That should then update the custom property with the label.
Credit goes to the below, there was another script that took that code a step further that may help.
Thank you guys for all your answers, I could do it:
In the end, this is my script:
data = self.props.options
for row in range(data.getRowCount()):
if (data.getValueAt(row, 0) == self.props.value):
self.custom.selectedLabel = data.getValueAt(row, 1)
break
Thank you.