From b7ecac9b4269205f8a454685f7113f8606ad8eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= Date: Tue, 13 Sep 2022 16:35:50 +0200 Subject: [PATCH] misc:fix block & map field (#67888) fix map init on block row add fix geocoding reverse for map field in block row --- wcs/qommon/static/js/qommon.forms.js | 1 + wcs/qommon/static/js/qommon.geolocation.js | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/wcs/qommon/static/js/qommon.forms.js b/wcs/qommon/static/js/qommon.forms.js index 7a76893da..b3a253900 100644 --- a/wcs/qommon/static/js/qommon.forms.js +++ b/wcs/qommon/static/js/qommon.forms.js @@ -687,6 +687,7 @@ $(function() { const $new_blockrow = $new_block.find('.BlockSubWidget').last(); add_js_behaviours($('[data-field-id="' + block_id + '"]')); $('form').trigger('wcs:block-row-added'); + $(document).trigger('wcs:maps-init'); if ($new_block.find('[data-live-source]')) { $('form div[data-live-source]').parents('form').trigger('wcs:change', {modified_field: 'init'}); } diff --git a/wcs/qommon/static/js/qommon.geolocation.js b/wcs/qommon/static/js/qommon.geolocation.js index 5842d688b..cc3ec5ac8 100644 --- a/wcs/qommon/static/js/qommon.geolocation.js +++ b/wcs/qommon/static/js/qommon.geolocation.js @@ -102,6 +102,7 @@ $(function() { init_sync_from_template_address(); }); $(document).on('set-geolocation', function(event, coords, options) { + var widget_name = $(event.target).parents('div.widget').data('widget-name'); $.getJSON(WCS_ROOT_URL + '/api/reverse-geocoding?lat=' + coords.lat + '&lon=' + coords.lng, function(data) { unset_sync_callback() if (data.err) return; @@ -116,7 +117,7 @@ $(function() { } if (typeof(options) == 'undefined' || !options.force_house_number === false || data.address.house_number) { - geoloc_prefill('house', data.address.house_number); + geoloc_prefill('house', data.address.house_number, widget_name); } var number_and_street = null; var street = data.address.road; @@ -131,16 +132,16 @@ $(function() { } else if (!street && data.address.park) { street = data.address.park; } - geoloc_prefill('road', street); + geoloc_prefill('road', street, widget_name); if (street && data.address.house_number) { number_and_street = data.address.house_number + ' ' + street; } else { number_and_street = street; } - geoloc_prefill('number-and-street', number_and_street); - geoloc_prefill('postcode', data.address.postcode); - geoloc_prefill('city', data.address.village || data.address.town || data.address.city || data.address.locality || data.address.municipality || data.address.county); - geoloc_prefill('country', data.address.country); + geoloc_prefill('number-and-street', number_and_street, widget_name); + geoloc_prefill('postcode', data.address.postcode, widget_name); + geoloc_prefill('city', data.address.village || data.address.town || data.address.city || data.address.locality || data.address.municipality || data.address.county, widget_name); + geoloc_prefill('country', data.address.country, widget_name); $(document).trigger('wcs:set-last-auto-save'); set_sync_callback() });