-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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: When the options object has a field named value, the selected value automatically takes the value of that field instead of the entire object #7134
Dropdown: When the options object has a field named value, the selected value automatically takes the value of that field instead of the entire object #7134
Comments
If you give the anything but |
I see, but if my options have a key named value, how do I set optionValue prop to use the entire object ? |
You can't. You have to change the key name. |
But we don't always have control over the object structure especially when it's fetched from a backend we don't control.. |
@melloware what do you think ? |
@mohamadbdeir i think this has been reported before. Multliselect and DropDown seem to handle it differently. MultiSelect: const getOptionValue = (option) => {
if (props.useOptionAsValue) {
return option;
}
if (props.optionValue) {
const data = ObjectUtils.resolveFieldData(option, props.optionValue);
return data !== null ? data : option;
}
return option && option.value !== undefined ? option.value : option;
}; DropDown: const getOptionValue = (option) => {
const optionValue = props.optionValue ? ObjectUtils.resolveFieldData(option, props.optionValue) : option ? option['value'] : ObjectUtils.resolveFieldData(option, 'value');
return props.optionValue || ObjectUtils.isNotEmpty(optionValue) ? optionValue : option;
}; It looks like Multiselect has an extra |
PR submitted. |
Describe the bug
When the options objects for the Dropdown have a field named 'value' the selected value would use that as a value instead of the entire object. I'm not sure if that is a mistake or done on purpose but seems odd .
Reproducer
https://stackblitz.com/edit/stackblitz-starters-kmdg5m?file=src%2FApp.tsx
System Information
Steps to reproduce the behavior
Use the dropdown component, you can try and copy the one from the documentation, rename any field of the options objects and give it the the name 'value' and you will see that the selected value for the dropdown takes that value instead of the entire object
Expected behavior
It should define the selected value as the entire object and not a single field.
The text was updated successfully, but these errors were encountered: