Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed file upload issue when having file or image fields using … #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions cruds_adminlte/templates/cruds/ajax/_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@
{{ form.media }}
{% endif %}

<form
id="{{name}}_{{object.pk}}_addedit"
action="{% crud_inline_url base_model inline_model action namespace %}"
method="POST" enctype="multipart/form-data"
data-replace-inner="#{{name}}_editList"
data-ajax-submit=""
data-refresh-inner="#{{name}}_myList"
data-success="success"
onsubmit="return false;">
<form id="{{name}}_{{object.pk}}_addedit">
{% csrf_token %}
<div class="box-body row">
<div class="col-md-12">
Expand All @@ -30,13 +22,13 @@
<div class="form-group">
<div class="controls">
<button
id="{{name}}_{{object.pk}}_addedit_submit"
type="submit"
class="btn btn-primary">{% trans "Submit" %}</button>
id="{{ name }}_{{ object.pk }}_addedit_submit"
type="submit"
class="btn btn-primary">{% trans "Submit" %}</button>
<a href="javascript::void(0);"
onclick="$('#{{name}}_editList').html('');"
class="btn btn-danger"
data-dismiss="modal">{% trans "Cancel" %}</a>
onclick="$('#{{ name }}_editList').html('');"
class="btn btn-danger"
data-dismiss="modal">{% trans "Cancel" %}</a>
</div>
</div>
</div>
Expand All @@ -45,8 +37,8 @@

<script>
{% if form.helper %}
$(".modal select:first").val(1).trigger('change.select2');
$(".modal select:first").parent().parent().hide();
$(".modal select:first").val(1).trigger('change.select2');
$(".modal select:first").parent().parent().hide();
{% endif %}

function success() {
Expand All @@ -55,4 +47,27 @@

$('.modal #submit-id-submit').parent().parent().remove(); // FIXME: Remove the crispy buttons
$('#edit_modal').modal('show');

$("#{{ name }}_{{ object.pk }}_addedit").submit(function (e) {
e.preventDefault();

var formdata = new FormData(this);

$.ajax({
url: "{% crud_inline_url base_model inline_model action namespace %}",
type: "POST",
data: formdata,
mimeTypes: "multipart/form-data",
contentType: false,
cache: false,
processData: false,
success: function (data) {
ajaxGet($('#{{name}}_myList').data('refresh-url'), function(content) {
$('#{{name}}_myList').html(content)
});
$('#edit_modal').modal('hide');
}
});
});

</script>