diff --git a/wcs/qommon/static/js/qommon.geolocation.js b/wcs/qommon/static/js/qommon.geolocation.js index 62c6a1e58..755b925bf 100644 --- a/wcs/qommon/static/js/qommon.geolocation.js +++ b/wcs/qommon/static/js/qommon.geolocation.js @@ -113,9 +113,26 @@ function init_sync_from_template_address() { } } $(widget_selector).each(function(idx, elem) { - // enable manual address mode if there is an error in one of the manual address fields. + var $manual_checkbox = $(elem).find('input.wcs-manual-address'); if ($(elem).nextUntil('.template-address', '[data-geolocation].widget-with-error').length) { - $(elem).find('input.wcs-manual-address').prop('checked', true).trigger('change'); + // enable manual address mode if there is an error in one of the manual address fields. + $manual_checkbox.prop('checked', true).trigger('change'); + } else { + // enable manual address mode if a manual field has data while the select is empty + // (typically when going back to a previous page) + var has_val = $(elem).find('select').val(); + if (! has_val) { + var has_manual_var = false; + $(elem).nextUntil('.template-address', 'div[data-geolocation]').find('input').each(function(idx, manual_elem) { + if ($(manual_elem).val()) has_manual_var = true; + }) + $(elem).nextUntil('.template-address', 'div[data-geolocation]').find('textarea').each(function(idx, manual_elem) { + if ($(manual_elem).val()) has_manual_var = true; + }) + if (has_manual_var) { + $manual_checkbox.prop('checked', true).trigger('change'); + } + } } }); }