Merge pull request #11160 from uberbrady/improve_default_custom_field_value_on_asset_create

Fixed: #11098 - Smartly overwrite fields with default values for custom fields
This commit is contained in:
snipe 2022-05-18 16:12:12 -07:00 committed by GitHub
commit 8449b5ca1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -151,7 +151,12 @@
//now re-populate the custom fields based on the previously saved values
$('#custom_fields_content').find('input,select').each(function (index,elem) {
if(transformed_oldvals[elem.name]) {
$(elem).val(transformed_oldvals[elem.name]).trigger('change'); //the trigger is for select2-based objects, if we have any
{{-- 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*
if there is no new default custom field value coming from the model --}}
if({{ $item->id ? 'true' : 'false' }} || $(elem).val() == '') {
$(elem).val(transformed_oldvals[elem.name]).trigger('change'); //the trigger is for select2-based objects, if we have any
}
}
});