1
0
-1

Hi all,

I want to add and save GPS coordinate on a client account form.

The client account form is working ok.

I put one textfield for longitude and ont text filed for latitude. So I can save the data.

I created a custom HTML section on my form.

In the advance option, this is the html custom code I'm using.

 

<button onclick="getLocation()">Position</button>

<p id="demo"></p>

 

<script>
var x = document.getElementById("demo");

function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}

function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}

function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
x.innerHTML = "User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML = "Location information is unavailable."
break;
case error.TIMEOUT:
x.innerHTML = "The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML = "An unknown error occurred."
break;
}
}
</script>

This is working out of the box: I can see the Lon and Lat coordinate on the mobile version when I click the position button but IT ACTIVATE THE DEFAULT SAVE BUTTON of the form and the form save all the fields that have info in them but the coordinate are lost because they are not assign to any filelds.

#1-how can I activate the script for the position button without activating the script of the save button of the form page?

#2-how can I assign the gps return values to the textfields longitude and latitude

#3-Is there a way to get the coordinate with a button in a textfield but not save the form right away? I want to continue editing the client record and when done make one final save?

 

Thanks in advance

Spazio

 

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      1 & 3) return false in ur getLocation function will prevent the form submission.

      2) 2 ways to do this.

         a) adding 2 text fields to ur form and using FormUtil.getField to get the field and set value.

         b) In your custom html element, add 2 input tags with proper name. the custom html element will auto handle the saving and loading (need to tick "Auto populated saved value?").

       

        CommentAdd your comment...