From 083f3cf3dd03883db95bf709b32def20db84ad5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 19 Mar 2024 13:50:30 +0100 Subject: [PATCH] misc: check "manual address" box when a manual address has been entered (#88332) --- wcs/qommon/static/js/qommon.geolocation.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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'); + } + } } }); }