Changes to Models in the asset-edit screen maintain chosen values (#4781)
Fixed for #2195
This commit is contained in:
parent
f5f7a63a23
commit
061317866b
1 changed files with 15 additions and 2 deletions
|
@ -105,9 +105,15 @@
|
||||||
@section('moar_scripts')
|
@section('moar_scripts')
|
||||||
<script nonce="{{ csrf_token() }}">
|
<script nonce="{{ csrf_token() }}">
|
||||||
|
|
||||||
|
var transformed_oldvals={};
|
||||||
|
|
||||||
function fetchCustomFields() {
|
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();
|
var modelid = $('#model_select_id').val();
|
||||||
if (modelid == '') {
|
if (modelid == '') {
|
||||||
$('#custom_fields_content').html("");
|
$('#custom_fields_content').html("");
|
||||||
|
@ -123,8 +129,15 @@
|
||||||
_token: "{{ csrf_token() }}",
|
_token: "{{ csrf_token() }}",
|
||||||
dataType: 'html',
|
dataType: 'html',
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
data: data,
|
|
||||||
$('#custom_fields_content').html(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…
Add table
Reference in a new issue