Restore custom field checkbox and radio button values when switching model

This commit is contained in:
Marcus Moore 2024-07-02 16:14:04 -07:00
parent ddd4065c81
commit 29433882ea
No known key found for this signature in database

View file

@ -221,6 +221,17 @@
//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]) {
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,
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 --}}