Merge pull request #16817 from marcusmoore/fixes/restore-custom-field-values-on-asset-edit-v2

Maintain checkbox and radio custom field values on asset edit page
This commit is contained in:
snipe 2025-04-29 10:17:10 +01:00 committed by GitHub
commit 6dbfc8875b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -224,6 +224,17 @@
//now re-populate the custom fields based on the previously saved values //now re-populate the custom fields based on the previously saved values
$('#custom_fields_content').find('input,select').each(function (index,elem) { $('#custom_fields_content').find('input,select').each(function (index,elem) {
if(transformed_oldvals[elem.name]) { if(transformed_oldvals[elem.name]) {
if (elem.type === 'checkbox' || elem.type === 'radio'){
let shouldBeChecked = oldvals.find(oldValElement => {
return oldValElement.name === elem.name && oldValElement.value === $(elem).val();
});
if (shouldBeChecked){
$(elem).prop('checked', true);
}
return;
}
{{-- If there already *is* is a previously-input 'transformed_oldvals' handy, {{-- If there already *is* is a previously-input 'transformed_oldvals' handy,
overwrite with that previously-input value *IF* this is an edit of an existing item *OR* overwrite with that previously-input value *IF* this is an edit of an existing item *OR*
if there is no new default custom field value coming from the model --}} if there is no new default custom field value coming from the model --}}