From 949cfce3b4a5e802e305cdbd3c194e6858cf747f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 29 May 2020 09:33:54 +0200 Subject: [PATCH] misc: look for address details in more attributes (#43446) --- wcs/qommon/static/js/qommon.geolocation.js | 24 +++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/wcs/qommon/static/js/qommon.geolocation.js b/wcs/qommon/static/js/qommon.geolocation.js index 2326ed3a8..d458e5210 100644 --- a/wcs/qommon/static/js/qommon.geolocation.js +++ b/wcs/qommon/static/js/qommon.geolocation.js @@ -59,16 +59,26 @@ function geoloc_prefill(element_type, element_value) var data = $('.JsonpSingleSelectWidget.template-address select').select2('data'); if (data) { var number_and_street = null; - if (data[0].address.house_number && data[0].address.road) { - number_and_street = data[0].address.house_number + ' ' + data[0].address.road; + var address = undefined; + if (typeof data[0].address == "object") { + address = data[0].address; } else { - number_and_street = data[0].address.road; + address = data[0]; + } + var road = address.road || address.nom_rue; + var house_number = address.house_number || address.numero; + var city = address.city || address.nom_commune; + var postcode = address.postcode || address.code_postal; + if (house_number && road) { + number_and_street = house_number + ' ' + road; + } else { + number_and_street = road; } geoloc_prefill('number-and-street', number_and_street); - geoloc_prefill('house', data[0].address.house_number); - geoloc_prefill('road', data[0].address.road); - geoloc_prefill('city', data[0].address.city); - geoloc_prefill('postcode', data[0].address.postcode); + geoloc_prefill('house', house_number); + geoloc_prefill('road', road); + geoloc_prefill('city', city); + geoloc_prefill('postcode', postcode); } }); if ($('.qommon-map').length == 0 && $('.JsonpSingleSelectWidget.template-address').length == 0) {