Created
April 7, 2018 03:08
-
-
Save dantenovski/225e85ceb21f8484089b60d27759df8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// autocomplete.js | |
var componentForm = { | |
locality: 'long_name', | |
administrative_area_level_1: 'long_name', | |
country: 'long_name' | |
}; | |
for (var i = 0; i < place.address_components.length; i++) { | |
var addressType = place.address_components[i].types[0]; | |
if (componentForm[addressType]) { | |
locationObject[addressType] = place.address_components[i][componentForm[addressType]]; | |
} | |
} | |
document.getElementById('locality').value = locationObject.locality; | |
document.getElementById('administrative_area_level_1').value = locationObject.administrative_area_level_1; | |
document.getElementById('country').value = locationObject.country; | |
//=========================== | |
// component | |
componentDidMount(){ | |
const script = document.createElement("script"); | |
script.src = "./assets/js/autocomplete.js"; | |
document.body.appendChild(script); | |
} | |
... | |
handleLocationInput(e){ | |
const value = e.target.value; | |
const name = e.target.name; | |
console.log(`value is: ${value} and name is ${name}`); | |
} | |
... | |
<div> | |
<input type="text" id="locality" name="locality" | |
onChange={this.handleLocationInput} /> | |
<input type="text" id="administrative_area_level_1" name="administrative_area_level_1" | |
onChange={this.handleLocationInput} /> | |
<input type="text" id="country" name="country" | |
onChange={this.handleLocationInput} /> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment