misc: check "manual address" box when a manual address has been entered (#88332) #1286

Merged
fpeters merged 1 commits from wip/88332-manual-address-checked into main 2024-03-21 08:59:39 +01:00
1 changed files with 19 additions and 2 deletions

View File

@ -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');
}
}
}
});
}