How to access menu values in Dropdown widget?

Hi all,

I have the following code:

dropdown = Dropdown(label = ‘Select product’, button_type = ‘primary’, menu = [(‘product 1’, ‘1234’), (‘product 2’, ‘5678’)])
dropdown.on_change(‘value’, dropdown_handler)

``

In the handler I will always get the second tuple value of the menu item.

Is there any way to access the first tuple value (‘product 1’, ‘product 2’, enz…) ?

Hi Tony,

The first item in each tuple is just a label and is used just for rendering items inside a drop-down.

You can either duplicate them in the menu parameter, making it both a value and a label, like “[(‘product 1’, ‘product 1’), …]”, or just create a map of values to labels, and use it inside your on_change handler.

Regards,

Eugene

···

On Friday, January 26, 2018 at 12:10:14 AM UTC+7, Tony Halik wrote:

Hi all,

I have the following code:

dropdown = Dropdown(label = ‘Select product’, button_type = ‘primary’, menu = [(‘product 1’, ‘1234’), (‘product 2’, ‘5678’)])
dropdown.on_change(‘value’, dropdown_handler)

``

In the handler I will always get the second tuple value of the menu item.

Is there any way to access the first tuple value (‘product 1’, ‘product 2’, enz…) ?

I need to have both “display text” and an “unique identity” in the menu tuples so I can use them both in the Dropdown event handler.
I understand it is impossible to get there the first tuple value so I will have to do the work-around you suggested.

Thanks.

···

On Thursday, January 25, 2018 at 6:30:43 PM UTC+1, Eugene Pakhomov wrote:

Hi Tony,

The first item in each tuple is just a label and is used just for rendering items inside a drop-down.

You can either duplicate them in the menu parameter, making it both a value and a label, like “[(‘product 1’, ‘product 1’), …]”, or just create a map of values to labels, and use it inside your on_change handler.

Regards,

Eugene

On Friday, January 26, 2018 at 12:10:14 AM UTC+7, Tony Halik wrote:

Hi all,

I have the following code:

dropdown = Dropdown(label = ‘Select product’, button_type = ‘primary’, menu = [(‘product 1’, ‘1234’), (‘product 2’, ‘5678’)])
dropdown.on_change(‘value’, dropdown_handler)

``

In the handler I will always get the second tuple value of the menu item.

Is there any way to access the first tuple value (‘product 1’, ‘product 2’, enz…) ?