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
Dropdown: Init-Value not working if options have label,value properties #6589
Comments
I noticed that this is not an error. My problem here is noted in the docs:
So this is more a question than a Bug => How can I get and set the Object, even if it has a |
https://stackblitz.com/edit/vitejs-vite-tmd4yk?file=src%2FApp.tsx I changed your code a bit. This should work. |
That works, and I'm using it in other parts of my code. However, now if I need to work with that object, for example, in the onChange event, I need to find it within the options. So, that is an acceptable workaround but not a real solution for that problem. I guess you want to say, 'you cannot get an object directly from the component if it has a value property,' correct? |
You can get an object with |
@Rekl0w, I see your point; however, it feels wrong that the component works differently based on how something looks inside. If I pass, for example, @melloware Could we make that to a feature/enhancement request? What about an extra option "workWithObject" or something? :) |
Yes this has always been a weird contention with using Object vs Primitive and letting it know which JSON fields you mean to use for value and label. |
I would expect that if I do not set optionValue, that I get back whatever I throw in. |
@melloware just looked at the code const getOptionValue = (option) => {
return props.optionValue ? ObjectUtils.resolveFieldData(option, props.optionValue) : ObjectUtils.resolveFieldData(option, 'value') || option;
}; The question I have here is why it has been decided that it is a good idea to try to resolve |
Describe the bug
If Dropdown is filled with
{label: string, value: any}[]
the inital value isn't selected.Reproducer
https://stackblitz.com/edit/vitejs-vite-2prkbq?file=src%2FApp.tsx
PrimeReact version
10.6.5
React version
18.x
Language
ALL
Build / Runtime
Vite
Browser(s)
No response
Steps to reproduce the behavior
No response
Expected behavior
No response
The text was updated successfully, but these errors were encountered: