{% extends "qommon/forms/widget.html" %}
{% block widget-control %}
        <textarea id="form_{{widget.name}}" name="{{widget.name}}" cols="50" rows="10"
            {% if widget.required %}aria-requited="true"{% endif %}
                    {% for attr in widget.attrs.items %}{% if attr.1 %}{{attr.0}}="{{attr.1}}"{% endif %}{% endfor %}
                    >{{widget.value|default:""}}</textarea>
        <script>
        $(document).on('set-geolocation', function(event, coords) {
            $.getJSON('/api/reverse-geocoding?lat=' + coords.lat + '&lon=' + coords.lng, function(data) {
                var $widget = $('#form_{{widget.name}}');
                    console.log(data.address);
                if (data.address.road) {
                    $widget.val($widget.val() + data.address.road + ', ');
                } else if (data.address.pedestrian) {
                    $widget.val($widget.val() + data.address.pedestrian + ', ');
                }
            });
         });
        </script>
{% endblock %}
