2 Autocomplete Address When Adding New Family Shared by Alex Yarmolatii, The Promise Center 11 days ago 17.0 Administration / Finance, CRM, General, Operations, Web, Workflow Intermediate To provide predictive address autocomplete (street suggestions as you type), you’ll need to: - Add a custom JavaScript solution to the page (Pages → Page → Advanced → Page HTML or add script to the theme) that calls a geocoding API (Google Places, Mapbox, etc.). - You need to have the Google API key in Global Attributes. The key in the script uses Rock’s Global Attribute: {{ 'Global' | Attribute:'GoogleAPIKey' }} so you don’t have to hardcode your API key.Step 1 - Add Your Script to the PageGo to your Add Family page (or whichever one you want autocomplete on)One of the ways is to go to CMS → Pages → Internal Homepage → Manage → New FamilyAdd HTMP block and paste this script:<script src="https://maps.googleapis.com/maps/api/js?key={{ 'Global' | Attribute:'GoogleAPIKey' }}&libraries=places"></script><script>document.addEventListener("DOMContentLoaded", function() { // Wait for the address field to load var addressInput = document.querySelector("input[id$='_tbStreet1']"); if (addressInput) { var autocomplete = new google.maps.places.Autocomplete(addressInput, { types: ['address'], componentRestrictions: { country: 'us' } }); autocomplete.addListener('place_changed', function() { var place = autocomplete.getPlace(); // Try to populate City, State, Zip if found if (place.address_components) { let cityField = document.querySelector("input[id$='_tbCity']"); let stateField = document.querySelector("input[id$='_ddlState']"); let zipField = document.querySelector("input[id$='_tbPostalCode']"); place.address_components.forEach(component => { const type = component.types[0]; if (type === "locality" && cityField) cityField.value = component.long_name; if (type === "administrative_area_level_1" && stateField) stateField.value = component.short_name; if (type === "postal_code" && zipField) zipField.value = component.long_name; }); } }); }});</script>Save and test it.Go to your Add Family pageStart typing 123 Main StGoogle should start showing address suggestions Download File