reflex icon indicating copy to clipboard operation
reflex copied to clipboard

Question: Select with value and label

Open pedrovidal opened this issue 2 years ago β€’ 1 comments

Hello!

I'm pretty new to pynecone and don't know if it is possible, but I have a list of ids and associated names, and I would like to crate a select where the name was displayed but when the option was selected the value would be the associated id (or an object with name and id, but just the id would do). Looking on the documentation I could only find examples where the label and value were the same.

How could I do this? Is it possible? If not, is this feature in the pipeline?

pedrovidal avatar Jun 19 '23 12:06 pedrovidal

I don't think it is possible at the moment.

Though it should not be too complicated to find the id from the value. Assuming you have

options = [(1, "Option A"), (2, "Option B")]

You can define :

options_name = [opt[1] for opt in options]

options_rmap = {opt[1]: opt[0] for opt in options}

We will bring some improvements to the select component in the future, but until them you should be able to make do with the code above.

Lendemor avatar Jun 22 '23 15:06 Lendemor

I'd second this and try to get it more visibility somehow. Without being able to handle lists of key/value pairs of data this functionality is not particularly useful beyond trivial scenarios. A separated option/value item list for select and multiselect is needed quickly

shrike71 avatar Oct 21 '23 09:10 shrike71

This is possible now in the low-level select.

picklelo avatar Jun 03 '24 02:06 picklelo