From 05fa0f451df4e42af5631bb5a9e27825ebd63f6f Mon Sep 17 00:00:00 2001 From: "nicolo.carpignoli" Date: Wed, 24 Jun 2020 09:58:24 +0200 Subject: [PATCH 1/2] fix remove button bug and check lat & lng regexp --- components/map/map-pick-location.js | 43 +++++++++++++++-------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/components/map/map-pick-location.js b/components/map/map-pick-location.js index bc09f68..944c66e 100644 --- a/components/map/map-pick-location.js +++ b/components/map/map-pick-location.js @@ -61,30 +61,26 @@ function updateLatLngValue(lat, lng) { } function check_lat_lon(e) { - let regex_lat = /^(-?[1-8]?\d(?:\.\d{1,18})?|90(?:\.0{1,18})?)$/; - let regex_lng = /^(-?(?:1[0-7]|[1-9])?\d(?:\.\d{1,18})?|180(?:\.0{1,18})?)$/; let lat = document.getElementById(`latitude${e.target.name}`).value; let lng = document.getElementById(`longitude${e.target.name}`).value; - let validLat = regex_lat.test(lat); // 21.2908 - let validLng = regex_lng.test(lng); // -157.8305 - - // only fire invalid coords if length on both is not 0 - if (lat.length !== 0 && lng.length !== 0) { - if (validLat && validLng) { - array.push({ - id: e.target.name, - coords: [lat, lng], - lat: lat, - lng: lng, - number: window.locationNumber, - }) - updateMarker(); - updateLocationParam(); - } - else { - updateLatLngInnerHtmlInvalidCoords() - } + console.log(typeof lat) + let validLat = !isNaN(lat) && lat >= -90 && lat <= 90; + let validLng = !isNaN(lng) && lng >= -180 && lng <= 180; + + if (validLat && validLng) { + array.push({ + id: e.target.name, + coords: [lat, lng], + lat: lat, + lng: lng, + number: window.locationNumber, + }) + updateMarker(); + updateLocationParam(); + } + else { + updateLatLngInnerHtmlInvalidCoords() } } @@ -112,6 +108,11 @@ function createInput(name, i) { function deleteCoords(id) { + const inputTags = [...document.querySelectorAll('.num-tags')]; + if (inputTags.length <= 1) { + return; + } + if (id === 0) { return; } From dc51c0e5a33de13d8183e0e042c5d5a4b87885c1 Mon Sep 17 00:00:00 2001 From: "nicolo.carpignoli" Date: Wed, 24 Jun 2020 19:28:11 +0200 Subject: [PATCH 2/2] remove console log --- components/map/map-pick-location.js | 1 - 1 file changed, 1 deletion(-) diff --git a/components/map/map-pick-location.js b/components/map/map-pick-location.js index 944c66e..e24e3f5 100644 --- a/components/map/map-pick-location.js +++ b/components/map/map-pick-location.js @@ -64,7 +64,6 @@ function check_lat_lon(e) { let lat = document.getElementById(`latitude${e.target.name}`).value; let lng = document.getElementById(`longitude${e.target.name}`).value; - console.log(typeof lat) let validLat = !isNaN(lat) && lat >= -90 && lat <= 90; let validLng = !isNaN(lng) && lng >= -180 && lng <= 180;