Closed NielsvandenDries closed 1 year ago
I created the following JavaScript in "plugins/renatio/formbuilder/assets/js/geolocation.js"
window.onload = getLocation;
var x = document.getElementById("geoloc");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition)
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.setAttribute('value', position.coords.latitude + ", " + position.coords.longitude)
}
As a Field Type i created:
<div class="{{ wrapper_class }} form-group">
{% if label %}
<label for="{{ name }}" class="{{ label_class }}">{{ label }}</label>
{% endif %}
<input
id="geoloc"
type="geoloc"
name="{{ name }}"
class="{{ class }} form-control"
placeholder="{{ placeholder }}"
{{ custom_attributes|raw }}
disabled
>
<button onClick="window.location.reload();" type="button" class="btn btn-info" style="width: inherit;">Refresh GPS location</button>
{% if comment %}
<p class="help-block">{{ comment|raw }}</p>
{% endif %}
</div>
I looks good but the set value with the Javascript is not sent with the notification Mail nor set in the Log. Is there some that can help me with this?
Fixed it: It's working now
FieldType:
<div class="{{ wrapper_class }} form-group">
{% if label %}
<label for="{{ name }}" class="{{ label_class }}">{{ label }}</label>
{% endif %}
<input
id="geoloc"
type="geoloc"
name="{{ name }}"
class="{{ class }} form-control"
value=""
placeholder="{{ placeholder }}"
{{ custom_attributes|raw }}
>
<button onClick="window.location.reload();" type="button" class="btn btn-info" style="width: inherit;">Refresh GPS location</button>
{% if comment %}
<p class="help-block">{{ comment|raw }}</p>
{% endif %}
</div>
Wow, great work!
I will add this field in next version.
Wow, great work!
I will add this field in next version.
Cool, I use it to add GPS location when a field engineer is working on a utility site for TV/Internet (because there are no home numbers)
Forgot to document that the geolocation.js has to be added to RenderForm.php
Going to upload it to discussion board for you.
Is your feature request related to a problem? Please describe. The Request is not related to a Problem, Just a new feature.
Describe the solution you'd like I like to see a field type for Geolocation, if used is gived the user a latitude/longitude of his current location. The geolocation should automatic update and should be send in the notification via Mail.
Describe alternatives you've considered I tried to code it myself, but my knowledge of javascript is not that great, I myself had created a geolocation.js that provides the location, Then tried to place it in a disabled textfield but unfortunately it didn't work.
Additional context![Geolocation-screenshot-20221013](https://user-images.githubusercontent.com/115483885/195557978-61490da5-9aeb-4129-b389-fadf42b9118a.png)