function clearAddressFields() { $('#address-components').hide(); $('#street-number').val(''); $('#street-number').prop('disabled', true); $('#route').val(''); $('#locality').val(''); $('#postal-code').val(''); } function getAddressFiedlValue(addressComponents, $field){ let field = addressComponents.find(obj => obj.types.indexOf($field) > -1); return field != undefined?field.long_name:''; } function initialize() { let input = document.getElementById('field_location'); let options = { types: ['address'], componentRestrictions: { country: "de" } }; var autocomplete = new google.maps.places.Autocomplete(input, options); autocomplete.addListener("place_changed", () => { clearAddressFields(); const place = autocomplete.getPlace(); if (!place.geometry) return; var componentMap = { country: 'country', locality: 'locality', administrative_area_level_1 : 'administrative_area_level_1', administrative_area_level_2 : 'administrative_area_level_2', postal_code: 'postal_code', route: 'route', street_number : 'street_number', }; $('#address-components').show(); let addressComponents = autocomplete.getPlace().address_components; let streetNumber = getAddressFiedlValue(addressComponents, 'street_number'); if(streetNumber == '') { $('#street-number').prop('disabled', false); $('#street-number').focus(); } else { $('#street-number').prop('disabled', true); $('#street-number').val(streetNumber); } let country = getAddressFiedlValue(addressComponents, 'country'); let route = getAddressFiedlValue(addressComponents, 'route'); $('#route').val(route); let locality = getAddressFiedlValue(addressComponents, 'locality'); $('#locality').val(locality); let postalCode = getAddressFiedlValue(addressComponents, 'postal_code'); $('#postal-code').val(postalCode); $('#street-number').blur(function(){ if($('#street-number').val() == '') $('#street-number').focus(); else{ $('#street-number').prop('disabled', true); $('#field_location').val(route+' '+$('#street-number').val()+', '+locality+', '+country); } }); }); } $(window).on('load', google.maps.event, initialize); let input = document.querySelector("#ctelefon"); let iti = window.intlTelInput(input, { initialCountry: "de", preferredCountries: ["de"], geoIpLookup: function(callback) { $.get('https://ipinfo.io', function() {}, "jsonp").always(function(resp) { let countryCode = (resp && resp.country)?resp.country:"us"; callback(countryCode); }); }, utilsScript: "{{storage('assets/libs/intl-tel-input/js/utils.min.js')}}", }); // iti.getNumber(); function updateProducts(){} $(window).on('load', function(){ $('#anfrage').submit(function(){ objProducts = []; localStorage.setItem("products", JSON.stringify(objProducts)); }); });