Option with value 0 has different behavior than any other number in dropdown
Describe the bug
Hi,
Seems like the behavior has been changed by commit 7312fe466e189581c53c3fe43bf3381db4b59455.
return props.optionValue ? ObjectUtils.resolveFieldData(option, props.optionValue) : ObjectUtils.resolveFieldData(option, 'value') || option;
The || here passes option through if the value is 0.
0 || "Test" == "Test" true
Reproducer
No response
PrimeReact version
10.6.5
React version
18.x
Language
TypeScript
Build / Runtime
Create React App (CRA)
Browser(s)
No response
Steps to reproduce the behavior
No response
Expected behavior
No response
cc @Rekl0w
it probably needs to be ObjectUtils.isNotEmpty(props.optionValue)
No, it is weird that i tried almost everything but not works for this. I also tried to use old version of this function but still the same behavior. I guess this is another bug. @melloware
The case where I tested was for the one with the 'value' key set. Maybe the isNotEmpty should check the output of resolveFieldData?
const getOptionValue = (option) => {
if (props.optionValue) {
return ObjectUtils.resolveFieldData(option, props.optionValue);
} else {
const optionValue = ObjectUtils.resolveFieldData(option, "value");
return ObjectUtils.isNotEmpty(optionValue) ? optionValue : option;
}
};
Edit: Or maybe use
const getOptionValue = (option) => {
if (props.optionValue) {
return ObjectUtils.resolveFieldData(option, props.optionValue);
} else {
return option.hasOwnProperty("value") ? ObjectUtils.resolveFieldData(option, "value") : option;
}
};
Both codes causes the blank dropdown options.
If you try the old codes before i've changed, it behaves the same. Like i said i don't think that code causes this bug.
Ok. I'll test some more tomorrow
Fixed with: https://github.com/primefaces/primereact/pull/7083