Projet

Général

Profil

0001-js-wait-a-bit-for-geocoding-before-going-on-with-for.patch

Frédéric Péters, 17 septembre 2020 19:41

Télécharger (2,16 ko)

Voir les différences:

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

 wcs/qommon/static/js/qommon.forms.js       | 18 ++++++++++++++++++
 wcs/qommon/static/js/qommon.geolocation.js |  3 +++
 2 files changed, 21 insertions(+)
wcs/qommon/static/js/qommon.forms.js
212 212
       * the same page; enable it back after a few seconds. */
213 213
      setTimeout(function() { $form.removeClass('disabled-during-submit'); }, 3000);
214 214
    }
215
    if ($form[0].wait_for_changes) {
216
      var waited = 0;
217
      var $button = $(event.originalEvent.submitter);
218
      if (! $button.is('button')) {
219
        $button = $('form .buttons .submit-button button');
220
      }
221
      var wait_id = setInterval(function() {
222
	waited += 1;
223
	if (! $form[0].wait_for_changes) {
224
	  clearInterval(wait_id);
225
	  $button.click();
226
	  return;
227
	} else if (waited > 5) {
228
	  $form[0].wait_for_changes = false;
229
	}
230
      }, 200);
231
      return false;
232
    }
215 233
    return true;
216 234
  });
217 235
  var live_evaluation = null;
wcs/qommon/static/js/qommon.geolocation.js
118 118

  
119 119
  function set_sync_callback() {
120 120
    var $map = $('.qommon-map');
121
    var $form = $map.parents('form');
122
    $form[0].wait_for_changes = false;
121 123
    if (! $map.data('address-sync')) return;
122 124
    $('div[data-geolocation]').on('change', 'input[type=text], textarea, select', function(event) {
125
      $form[0].wait_for_changes = true;
123 126
      var address = '';
124 127
      var found_city = false;
125 128
      $(['number-and-street', 'house', 'road', 'postcode', 'city', 'country']).each(function(idx, elem) {
126
-