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) {