js: wait a bit for geocoding before going on with form submit (#46762)

This commit is contained in:
Frédéric Péters 2020-09-17 19:39:02 +02:00
parent 18d9fea6ff
commit 10a2709d03
2 changed files with 23 additions and 0 deletions

View File

@ -262,6 +262,24 @@ $(function() {
* the same page; enable it back after a few seconds. */
setTimeout(function() { $form.removeClass('disabled-during-submit'); }, 3000);
}
if ($form[0].wait_for_changes) {
var waited = 0;
var $button = $(event.originalEvent.submitter);
if (! $button.is('button')) {
$button = $('form .buttons .submit-button button');
}
var wait_id = setInterval(function() {
waited += 1;
if (! $form[0].wait_for_changes) {
clearInterval(wait_id);
$button.click();
return;
} else if (waited > 5) {
$form[0].wait_for_changes = false;
}
}, 200);
return false;
}
return true;
});
var live_evaluation = null;

View File

@ -119,8 +119,12 @@ function geoloc_prefill(element_type, element_value)
function set_sync_callback() {
var $map = $('.qommon-map');
if ($map.length == 0) return;
var $form = $map.parents('form');
$form[0].wait_for_changes = false;
if (! $map.data('address-sync')) return;
$('div[data-geolocation]').on('change', 'input[type=text], textarea, select', function(event) {
$form[0].wait_for_changes = true;
var address = '';
var found_city = false;
$(['number-and-street', 'house', 'road', 'postcode', 'city', 'country']).each(function(idx, elem) {
@ -146,6 +150,7 @@ function geoloc_prefill(element_type, element_value)
map.marker.addTo(map);
}
$map.trigger('set-geolocation', coords, {'trigger': false});
$form[0].wait_for_changes = false;
}
});
}