tlodge
4 weeks ago

Algolia Places removing the first line of address before submitted

Posted 4 weeks ago by tlodge

I've set up a form on a page, with two address fields for different people. The first submits fine, the second address is found fine by Algolia places and the Line 2, city and postcode are all filled in. But when submitted the first line of the address is not submitted. If I remove Algolia places then the form submits correctly so it seems to be a JS error rather than a laravel. Here's my code below if it helps

(function() {
  var placesAutocomplete = places({
    appId: 'plCA19E07224',
    apiKey: '073a4e056abca25a45f9b855a802beb5',
    container: document.querySelector('#address'),
    templates: {
      value: function(suggestion) {
        return suggestion.name;
      }
    }
  }).configure({
    type: 'address'
  });
  placesAutocomplete.on('change', function resultSelected(e) {
    document.querySelector('#address2').value = e.suggestion.suburb || '';
    document.querySelector('#addresscity').value = e.suggestion.city || '';
    document.querySelector('#addresspostcode').value = e.suggestion.postcode || '';
  });
})();
</script>
<script>
(function() {
  var placesAutocomplete2 = places({
    appId: 'plCA19E07224',
    apiKey: '073a4e056abca25a45f9b855a802beb5',
    container: document.querySelector('#partnersaddress'),
    templates: {
      value: function(suggestion) {
        return suggestion.name;
      }
    }
  }).configure({
    type: 'address'
  });
  placesAutocomplete2.on('change', function resultSelected(e) {
    document.querySelector('#partnersaddress2').value = e.suggestion.suburb || '';
    document.querySelector('#partnersaddresscity').value = e.suggestion.city || '';
    document.querySelector('#partnersaddresspostcode').value = e.suggestion.postcode || '';
  });
})();
</script>

Please sign in or create an account to participate in this conversation.