Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use value of objects? #3333

Closed
Lekha30 opened this issue Jan 9, 2019 · 3 comments
Closed

How to use value of objects? #3333

Lekha30 opened this issue Jan 9, 2019 · 3 comments

Comments

@Lekha30
Copy link

Lekha30 commented Jan 9, 2019

May be related to #858

Are you reporting a bug or runtime error?

I am trying to use values of objects for the select options:
option:1 {label: "Age-5", value:{name:"Age", value:"5"}}.
option:1 {label: "Age-5", value:{name:"Age", value:"5"}}.
option:1 {label: "Age-5", value:{name:"Age", value:"5"}}.

But When the options are chosen, they don't get matched against the selected values 👍
image

I have tried valueRenderer option too, but can't quite get that to working. Any pointers to fix this is much appreciated.

Thanks

@reeversedev
Copy link

Have you tried Object.values()?

@mathesmyhotelshop
Copy link

mathesmyhotelshop commented Apr 22, 2019

I was able to use objects as options.

Having

const dogs = [ { id: 1, name: 'dog1' }, { id: 2, name: 'dog2' }, { id: 3, name: 'dog3' } ];
const selectedOption = dogs[0];

the code

<Select
    options={dogs}
    value={selectedOption}
    getOptionLabel={(dog) => dog.name}
    getOptionValue={(dog) => dog.id}
    onChange={console.log}
/>

will display 'dog1' as selected value and on select it will call console.log with the corresponding selected dog as object, e.g. { id: 2, name: 'dog2' }.

I found this solution in the advanced docs.

@Lekha30
Copy link
Author

Lekha30 commented Apr 23, 2019

Thanks for that. I tried managing it using parse and format props

@Lekha30 Lekha30 closed this as completed Apr 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants