Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix remove button bug and check lat & lng regexp #81

Merged
merged 2 commits into from
Jun 24, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions components/map/map-pick-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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;
}
Expand Down