Expose full value object in `onSelectOption`
See original GitHub issueAlright I just got it all setup again and this was the issue…
<AutoCompleteItem
key={idx}
value={address}
getValue={(address: AddressRecommendation) => address.address}
>
{address.address}
</AutoCompleteItem>
The above works as expected, but when I select an item and set a debugger within onSelection
, here’s what selectedOption
is:
For my use case, I would expect selectedOption.item.value
to be the full object so I could set the selected address
and placeId
, not just the value of the key I provided in getValue
. Make sense? I wouldn’t make this change without getting input from others, especially since it’s a breaking change, but hopefully that clears up what my intent was.
_Originally posted by @SpencerKaiser in https://github.com/anubra266/choc-autocomplete/issues/60#issuecomment-1023484143_
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:5 (5 by maintainers)
Top Results From Across the Web
onChange returns the selected value, not the complete event
onChange simply returns the new value and label and not the whole event. I understand we can use the hidden input field to...
Read more >how to pass an object to an onchange function? (Select option)
I have an select dropdown inside a table and when I'm trying to select an option I want to send ...
Read more >ASP.NET Core Blazor data binding - Microsoft Learn
Sets an <input> element's value to a password field. Exposes changes of a Password property to a parent component with an EventCallback that ......
Read more >API - React Select
The statemanager is a utility class that wraps around the base Select and each Select variant to expose inputValue and value as controllable...
Read more >React Hooks cheat sheet: Best practices with examples
useRef returns a “ref” object. Values are accessed from the .current property of the returned object. The .current property could be initialized ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In my opinion having the
value
in theitem
not match thevalue
passed toAutoCompleteItem
is sort of a bug. It’s confusing that they are not the same. One would expect that if you pass in a value you get the same value back when selected.Although it’s a breaking change to change it to the full object, I think it’s the solution that makes the most sense in the long run.
However, looking at the code, the simplest solution is to just add an
originalValue
field toitem
that contains the original value object.I don’t think that is a good idea to merge the objects. What if the full object already has a
label
andvalue
field? Then you’ll have a key collision if you try to merge the fields from the full object intoitem
.