-
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
AutoComplete: shows "[object Object]" if value object instance is not one of suggestions #1392
Comments
Likely a bug introduced by the #1296 fix. |
@VsevolodGolovanov @aloker Any luck with this issue and a fix for it? I'm running into this issue too.
With the above setup, whenever API fails, an error message shows in the autocomplete dropdown. But, the problem is, if the user clicks on the Error message, the autocomplete renders |
@kashifshamaz21 , in your case I'd try working around the issue by preventing the error value from being selected. In your onChange or onSelect, if the new value is an error, then either leave the current value unchanged or set to null/undefined. |
This is not some obscure edge case btw. Showing projections for text search results, and only turning a projection into a full fledged object when user actually selects it - this is the most normal thing in the world. |
If there are no plans to fix this, consider rolling back the #1296 fix? At least that issue could be worked around trivially. |
I don't think it is correct to directly return the 'value' based on the type of 'value'. Users can define value differently and return a different value from selectedItemTemplate. My personal opinion for this issue is to assign the value given as value to the suggestion object. For your example;
You can directly change the suggestion in any query. It totally depends on your implementation. |
1. A suggestion object often contains stuff like matched string and info for highlighting. Those are not a part of the domain object represented by the suggestion. A suggestion object could contain the corresponding domain object. In fact that's how it is in my actual code:
I think this must be supported, the API just wouldn't make sense otherwise. 2. The next level would be to support values not coming from suggestions at all, but created in onSelect. Would be great if this were supported, but it's not as quintessential as 1. |
I'm submitting a ... (check one with "x")
Codesandbox Case (Bug Reports)
https://codesandbox.io/s/primereact-test-yus1p
Current behavior
Initial value object is shown as "[object Object]" in the autocomplete field.
Selected value object is shown as "[object Object]" in the autocomplete field.
Expected behavior
Value objects should be shown using the provided
selectedItemTemplate
function.Minimal reproduction of the problem with instructions
Open the showcase. See "[object Object]" in the field.
Type something into the field, select one of the suggestions. See "[object Object]" in the field.
Please tell us about your environment:
React version:
16.3.1
PrimeReact version:
4.2.1
Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
Firefox 77.0.1
Language: [all | TypeScript X.X | ES6/7 | ES5]
The text was updated successfully, but these errors were encountered: