question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expose full value object in `onSelectOption`

See original GitHub issue

Alright 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: image

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:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
jcdogocommented, Feb 5, 2022

In my opinion having the value in the item not match the value passed to AutoCompleteItem 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 to item that contains the original value object.

2reactions
jcdogocommented, Feb 5, 2022

I don’t think that is a good idea to merge the objects. What if the full object already has a label and value field? Then you’ll have a key collision if you try to merge the fields from the full object into item.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found