Getting extra data from input value

Hi everyone,

I have some data that I am using to populate the options of an input selector. The data looks something like this:

{
    "name": "Option 1",
    "id": "899df70d-c13b-4a79-9627-febc354dc896"
},
{
    "name": "Option 2",
    "id": "a5119000-6c76-49c8-aa37-2cb89443edf7"
}

I used the map function to convert this to the below, so that it is accepted by my input selector

["Option 1", "Option 2"]

Now the problem is when the value changes, I need to grab the ID of the option that was selected, but this is no longer available because the ID of the option isn’t contained within the value itself.

In this simplified example, I could just use a function to find the id where the value equals name. But this doesn’t seem like a very polished solution (what if there are two options with the same name?).

What’s the best way to handle this?

I was just browsing the recent posts and someone linked this video, which explains how to add a different label and input.

What a coincidence, I had looked for a while before posting :grinning:

3 Likes

Hi @mal

Yes, you can keep both pieces of information (name and ID) by setting label Field to “name”, and valueField to “id”, so you can know which ID goes with which name. Let me know if it’s working for you.

And if you are interested in more than the ID option I had this question and Joyce had created a video with more than ID: Icon in a select input - #2 by Joyce