From 981741062bebbfbaca9e4104f8763115c6ffb944 Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Wed, 18 May 2022 15:51:32 -0700 Subject: [PATCH] Try to intelligently overwrite fields with default values for custom field --- resources/views/hardware/edit.blade.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/resources/views/hardware/edit.blade.php b/resources/views/hardware/edit.blade.php index 20e93f067..42af51834 100755 --- a/resources/views/hardware/edit.blade.php +++ b/resources/views/hardware/edit.blade.php @@ -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, + only overwrite with previously that value *IF* this is an edit of an existing item *OR* + 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 + } } });