mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Changes to Models in the asset-edit screen maintain chosen values (#4781)
Fixed for #2195
This commit is contained in:
parent
f5f7a63a23
commit
061317866b
|
@ -105,9 +105,15 @@
|
|||
@section('moar_scripts')
|
||||
<script nonce="{{ csrf_token() }}">
|
||||
|
||||
|
||||
var transformed_oldvals={};
|
||||
|
||||
function fetchCustomFields() {
|
||||
//save custom field choices
|
||||
var oldvals = $('#custom_fields_content').find('input,select').serializeArray();
|
||||
for(var i in oldvals) {
|
||||
transformed_oldvals[oldvals[i].name]=oldvals[i].value;
|
||||
}
|
||||
|
||||
var modelid = $('#model_select_id').val();
|
||||
if (modelid == '') {
|
||||
$('#custom_fields_content').html("");
|
||||
|
@ -123,8 +129,15 @@
|
|||
_token: "{{ csrf_token() }}",
|
||||
dataType: 'html',
|
||||
success: function (data) {
|
||||
data: data,
|
||||
$('#custom_fields_content').html(data);
|
||||
$('#custom_fields_content select').select2(); //enable select2 on any custom fields that are select-boxes
|
||||
//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
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue