Search code examples
javascriptreact-nativefocusgoogle-places-autocomplete

How to get focus from click event of a text to googleplaces autocomplete input?


need your help for an app iam trying to develop. So I have used react native googleautoplaces complete for the location, which is shown in the first text input.

The page when loaded gets the current location based on geocoder, geolocation codes i have used.

What i need is that, when i click on the 'change' link, it should focus or select the location input.page design,code for google autocomplete,code2.

If i use ref, can i do like that. If yes, how to add multiple ref, because already another ref is used in the autocomplete.ref method used inside autocomplete, which takes the address value.


Solution

  • <GooglePlacesAutocomplete 
    ...
    ref={(ref) => { this.ref_location = ref }
    
    //your element where the "Change" is being pressed. I used a button just as an example
    
    <Button
        title="Change"
        onPress={() => { this.ref_location.focus(); }}
    />