#MultiSelect, extra fields

21 messages · Page 1 of 1 (latest)

crystal kindle
#

Hi everyone,

I'm trying to create a MultiSelect with an object as the value, but I've come to the issue that the MultiSelect won't show my selected values.

Is there a way to display my selected values or is there another way to pass extra fields?

fresh bear
#

could you show some code/make a minimal codesandbox?

crystal kindle
#

MultiSelect element

<MultiSelect
  data={multiSelectData}
  label="Products"
  description="Select products"
/>

multiSelectData

const multiSelectData = [
  { label: "produc1", value: { itemID: 1, label: "product1"}}
]
#

MultiSelect is controlled (Left it out for better readability)

#

I map over the MultiSelect value and create a <TextArea> for each selected product

#

and I want to display the label of the product in the label of the TextArea

crystal kindle
#

I tried to fix it setting the valueComponent prop like this:

#

But there is no remove button

#

and re-coding that would seem silly

fresh bear
#

yeah that's your problem - do value: ${yourItemIdVariable}

#

label and value should he strings otherwise it will give you problems

crystal kindle
#

Okay

#

Can I just add extra fields to my multiSelectData object?

fresh bear
#

you can make an object or map lookup, using your IDs to look up your full extended objects based on the ID value

crystal kindle
#

I assume it's not possible to send the label prop to the MultiSelect value?

#

Because it only sends the value

fresh bear
#

no, they're separate

#

you can make label and value exactly the same if you want, you can also use string[] if you want them both to be the same

crystal kindle
#

yeah I need both label and itemid, but I'll just search in the array of products for a matching itemID