Hi,
I'm currently using jQuery-File-Upload from inside a bootstrap modal dialog, containing an "Add a file" button.
The upload works perfectly fine, but I'm getting some trouble reinitializing the whole stuff once the user re-opens the modal.
I wish every time the use reopens the modal, the jQuery-Upload-File GUI could be empty (ie not showing previously sent files).
For this, I thought about :
- initializing the jquery-fileupload on bootstrap show event,
- and then calling fileupload('destroy') on bootstrap close event
I tried this :
$('#providersUploadModal').on('shown.bs.modal', function () {
$('#fileupload').fileupload({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
url: '/application/third_party/libs/jQuery-File-Upload/server/php/',
sequentialUploads: true,
autoUpload: true,
acceptFileTypes: /(\.|\/)(tgz)$/i,
maxFileSize: 500000, // 5OO KB
});
// Enable iframe cross-domain access via redirect option:
$('#fileupload').fileupload(
'option',
'redirect',
window.location.href.replace(
/\/[^\/]*$/,
'/application/third_party/libs/jQuery-File-Upload/cors/result.html?%s'
)
);
});
And then destroy when bootstrap hide event occurs :
// Destroy #fileupload on modal close
$('#providersUploadModal').on('hidden.bs.modal', function () {
$('#fileupload').fileupload('destroy');
})
This seems not to destroy the previously upload files list, nor delete all event bindinds. I write this because I also tried this :
// Destroy #fileupload on modal close
$('#providersUploadModal').on('hidden.bs.modal', function () {
$('#fileupload').fileupload('destroy');
$('#fileupload table tbody').children().remove()
})
And from what I can see, although the list is empty, asking for uploading a file prevously uploaded actually adds two more lines in the table without even uploading them.
Thank you.