react-native-google-places-autocomplete
                                
                                 react-native-google-places-autocomplete copied to clipboard
                                
                                    react-native-google-places-autocomplete copied to clipboard
                            
                            
                            
                        Feature Request: setaddressText using ref should trigger search
Describe the bug
I am saving recently searched terms in my state and when user clicks on one of the recent searches, I do this.autoCompleteRef.setAddressText(this.state.recentSearch). This updates the text input value but the search is not triggered. I have to press one more key to see the search results from place autocomplete api
Reproduction - (required - issue will be closed without this)
Steps to reproduce the behavior - a minimal reproducible code example, link to a snack or a repository.
Please provide a FULLY REPRODUCIBLE example.
Click to expand!
<GooglePlacesAutocomplete
            ref={comp => (this.autoCompleteRef = comp)}
            placeholder="Search"
            styles={{textInput: {borderBottomColor: "#4a4a4a", borderBottomWidth: 1, backgroundColor: 'transparent'}}}
            onPress={(data, details = null) => {
              // 'details' is provided when fetchDetails = true
              console.log(data);
              console.log(details);
            }}
            query={{
              key: 'key',
              language: 'en',
              components: 'country:in',
            }}
            currentLocation={true}
            currentLocationLabel="Use your current location"
            nearbyPlacesAPI="GoogleReverseGeocoding"
            textInputProps={{onBlur: () => {}}}
            fetchDetails //details.geometry.location - gives lat, lng
          />
         handleRecentLocationClick = (desc) => {
         this.autoCompleteRef.setAddressText(desc)
         this.autoCompleteRef.focus()
}
Please remember to remove you google API key from the code you provide here
Additional context
- 
Library Version: [e.g. 1.4.2] 
- 
React Native Version: [e.g. 0.62.2] 
- 
[ ] iOS 
- 
[x] Android 
- 
[ ] Web 
If you are using expo please indicate here:
- [ ] I am using expo
Add any other context about the problem here, screenshots etc
You need this.autoCompleteRef.triggerFocus() before version 2.
https://github.com/FaridSafi/react-native-google-places-autocomplete/releases/tag/v2.0.0
Hello @bell-steven i am on version 2.0.3 "react-native-google-places-autocomplete": "^2.0.3"
Ok. Can you try using version 2.1.1. There were some changes in v2.1.0 that may have addressed the issue.
Ok. Can you try using version 2.1.1. There were some changes in v2.1.0 that may have addressed the issue.
v 2.1.1 here and got the same issue. The textinput is updated, but the search is not triggered.
Ok. Can you try using version 2.1.1. There were some changes in v2.1.0 that may have addressed the issue.
i am having the same issue as well. Textinput triggered, but search not.
Same here using v2.1.2.
Is there any solution for this bug? The same issue I am facing search is not triggered with a predefined text.
Does anyone found a solution for this bug?
For anyone still having trouble with this I managed to make it work. I'm on version 2.4.1 and you need to change a line in GooglePlacesAutocomplete.js inside react-native-google-places-autocomplete in node_modules. The problem seems to be that the useEffect at line 145 that is in charge of populating the results list runs before the local state variable stateText is updated from the setAddressText method. If you change line 161 from setStateText(address) to _handleChangeText(address) it should work.
For anyone still having trouble with this I managed to make it work. I'm on version 2.4.1 and you need to change a line in
GooglePlacesAutocomplete.jsinsidereact-native-google-places-autocompleteinnode_modules. The problem seems to be that theuseEffectat line 145 that is in charge of populating the results list runs before the local state variablestateTextis updated from thesetAddressTextmethod. If you change line 161 fromsetStateText(address)to_handleChangeText(address)it should work.
This works! Remember to this.autocompleteRef.focus() to display the results list.
Does someone want to put in a PR?
Does someone want to put in a PR?
Done!
GooglePlacesAutocomplete.jsinsidereact-native-google-places-autocompleteinnode_modules. The problem seems to be that theuseEffectat line 145 that is in charge of populating the results list runs before the local state variablestateTextis updated from thesetAddressTextmethod. If you change line 161 fromsetStateText(address)to_handleChangeText(address)it should work.This works! Remember to this.autocompleteRef.focus() to display the results list.
I tried this and works, is there any way to make it auto update after every character input?
this.autocompleteRef.focus()
where would you put this
has this issue been resolved yet ? and if yes its not updated on the docs