react-places-autocomplete icon indicating copy to clipboard operation
react-places-autocomplete copied to clipboard

Returning the full suggestion object in onSelect

Open Frexuz opened this issue 6 years ago • 10 comments

Do you want to request a feature or report a bug? Feature

What is the current behavior? onChange and onSelect (internally handleSelect) only return limited data:

https://github.com/hibiken/react-places-autocomplete/blob/master/src/PlacesAutocomplete.js#L349

    const { description, placeId } = suggestion;
    this.handleSelect(description, placeId);

Why not return the full suggestion object? At this moment, I can't get suggestion.terms from these methods. The full suggestion object is only available when rendering children

What is the expected behavior? onChange and onSelect should return the full suggestion object

Which versions of ReactPlacesAutocomplete, and which browser / OS are affected by this issue? react-places-autocomplete@^7.2.0

Frexuz avatar Aug 02 '18 14:08 Frexuz

I agree that's a good question... It would be more useful ! And more consistent too 😅

theophanemayaud avatar Aug 02 '18 14:08 theophanemayaud

I tried to fork it, but the source is not a compiled package. Not sure how to handle a non compiled node_module with webpacker :D Even tho my config uses babel-loader, my app can't find the package 🤔 While your package has the /dist folder

Frexuz avatar Aug 02 '18 14:08 Frexuz

Can't you build it first ?

theophanemayaud avatar Aug 02 '18 15:08 theophanemayaud

Do you mean Suggestion object, as the object data in which the place name comes from? So far I can only return address details, but I want to try and return the place details on click, such as place name and telephone number.

TommyJackson85 avatar Aug 05 '18 17:08 TommyJackson85

Fixed like this in my (private) fork :) screen shot 2018-08-06 at 17 12 37

Frexuz avatar Aug 06 '18 09:08 Frexuz

Looks like there's already a PR for this: #226. I would also love to see this feature!

lnhrdt avatar Aug 14 '18 02:08 lnhrdt

Any progress with this one? I stupidly started using this without checking if it actually returned useful data, but with just the string it's not too handy.

YCMitch avatar Aug 17 '18 01:08 YCMitch

Just merge the PR please! :)

Frexuz avatar Aug 17 '18 06:08 Frexuz

If you want the structured address, you can use the util geocodeByPlaceId and the placeId to get the address_components. That way you don't need to try and parse out the address yourself

WickyNilliams avatar Mar 20 '19 18:03 WickyNilliams

I didn't even see this issue before implementing #319. Good to know that others will benefit from this as well :). It's currently in review and will be merged soon.

Related: #226

sambokai avatar May 17 '20 10:05 sambokai