Commit fcacdc9f authored by Thalia Technicie's avatar Thalia Technicie Committed by Sébastiaan Versteeg

Add Google Autocomplete

parent dfc2d8a7
......@@ -20,4 +20,32 @@ $(function() {
changeVisiblity(this.value);
});
}
var input = document.querySelector('#id_address_street');
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.addListener('place_changed', function () {
var place = autocomplete.getPlace();
var getAddressItem = function(type, length) {
var address = place.address_components;
var addressItem = address.find(function (item) {
return item.types.includes(type);
});
var key = length + '_name';
return addressItem && addressItem[key] ? addressItem[key] : '';
};
$('#id_address_street').val(
getAddressItem('route', 'long') + ' '
+ getAddressItem('street_number', 'long'));
$('#id_address_city').val(
getAddressItem('locality', 'long'));
$('#id_address_postal_code').val(
getAddressItem('postal_code', 'long'));
$('#id_address_country').val(
getAddressItem('country', 'short').toUpperCase());
});
});
......@@ -3,6 +3,15 @@
{% block title %}{% trans "registration"|capfirst %} — {{ block.super }}{% endblock %}
{% block js_body %}
{{ block.super }}
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key={{ google_api_key }}&libraries=places"></script>
{% compress js %}
<script type="text/javascript" src="{% static 'registrations/js/main.js' %}"></script>
{% endcompress %}
{% endblock %}
{% block body %}
<section class="page-section" id="registrations-form">
<div class="container">
......
......@@ -150,6 +150,11 @@ class MemberRegistrationFormView(BaseRegistrationFormView):
form_class = forms.MemberRegistrationForm
template_name = 'registrations/register_member.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['google_api_key'] = settings.GOOGLE_MAPS_API_KEY
return context
def post(self, request, *args, **kwargs):
request.POST = request.POST.dict()
request.POST['language'] = request.LANGUAGE_CODE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment