Skip to content

Commit

Permalink
Stricter checks on address strings before mapping. Street must start …
Browse files Browse the repository at this point in the history
…with a digit and have at least two words. Check zip separately from street.
  • Loading branch information
ejk committed Jun 24, 2024
1 parent 04c7830 commit e77aa82
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions js/homecode_form.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
(function ($, Drupal) {
var lookupBtn = document.getElementById('edit-lookup-address');
lookupBtn.addEventListener('click', function() {
var address = document.getElementById('edit-street').value + ' ' + document.getElementById('edit-zip').value;
geocode_address(address.trim());
geocode_address(document.getElementById('edit-street').value.trim(), document.getElementById('edit-zip').value.trim());
}, false);

// Build marker layers
Expand All @@ -29,15 +28,18 @@

myMap.on('click', onMapClick);

function geocode_address(address) {
if (address == '') {
setMapError("*Please enter address and zip code");
function geocode_address(street, zip) {
if (street.search(/[\d].* .+/) == -1) {
setMapError("*Please enter street number and street name");
}
else if (zip == '') {
setMapError("*Please enter zip code");
}
else {
// Pull data from geocode service
$.ajax({
type: 'GET',
url: '/summergame/geocode/' + address,
url: '/summergame/geocode/' + street + ' ' + zip,
dataType: 'json',
success: function (data) {
if (data.status == 'OK') {
Expand Down

0 comments on commit e77aa82

Please sign in to comment.