Fix #6733: add null check condition in getOptionValue(Dropdown)
Defect Fixes
- fix #6733
- example: https://stackblitz.com/edit/vitejs-vite-5esx3k?file=src%2FApp.jsx,package.json&terminal=dev
how to resolve
1. add null check
- when default value is 0, the selected option is not selected
- the
resolveFieldDatafunction returns null if the value is not found, so we need to check if the value is not null :)
// before
const getOptionValue = (option) => {
return props.optionValue ? ObjectUtils.resolveFieldData(option, props.optionValue) : ObjectUtils.resolveFieldData(option, 'value') || option;
};
// after
const getOptionValue = (option) => {
if (props.optionValue) {
return ObjectUtils.resolveFieldData(option, props.optionValue);
} else {
const dataValue = ObjectUtils.resolveFieldData(option, 'value');
return dataValue !== null ? dataValue : option; // null checking!
}
};
2. fix wrong check condition
hasSelectedOptionis function.
const hasSelectedOption = () => {
return ObjectUtils.isNotEmpty(props.value);
};
- I changed
hasSelectedOptiontohasSelectedOption()to ensure the condition evaluates the result of the function call rather than a function reference.
// before
const findSelectedOptionIndex = () => {
return hasSelectedOption ? visibleOptions.findIndex((option) => isValidSelectedOption(option)) : -1;
};
// after
const findSelectedOptionIndex = () => {
return hasSelectedOption() ? visibleOptions.findIndex((option) => isValidSelectedOption(option)) : -1;
};
result
https://github.com/primefaces/primereact/assets/37934668/3e4c5e13-0880-49e5-b6c1-e265cecfff3f
The latest updates on your projects. Learn more about Vercel for Git ↗︎
2 Skipped Deployments
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| primereact | ⬜️ Ignored (Inspect) | Visit Preview | Jul 3, 2024 9:29am | |
| primereact-v9 | ⬜️ Ignored (Inspect) | Visit Preview | Jul 3, 2024 9:29am |
Thank you for your patience during our national vacation. We encountered and resolved an issue with getOptionValue and getOptionLabel reported by one of our PRO users. We prioritized fixing this problem as soon as possible before reviewing GitHub issues.
We appreciate your contribution and would like to ask you to check the latest version of the master branch to see if everything works fine for you as well.
Thank you for your support and understanding. @KumJungMin
@nitrogenous Oh Sorry, I just checked wrong. I checked again and this issue was resolved in master. thank you for comment!
safe to close this PR and ticket?
@nitrogenous Oh Sorry, I just checked wrong. I checked again and this issue was resolved in master. thank you for comment!
I wish I had seen your pull request before. I am really sorry that we couldn't merge your PR. I would love to see your further contributions. Thank you for your support to our community
@nitrogenous I'm glad the issue was resolved quickly. Even though it wasn't merged, it was nice to be able to read a lot of the code while trying to contribute! Thank you again for your comment. Have a nice day 😄