misc: check "manual address" box when a manual address has been entered (#88332)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2024-03-19 13:50:30 +01:00
parent 520e52d1a7
commit 083f3cf3dd
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');
}
}
}
});
}