I'm trying to implement multiple jQuery File Upload forms to a page, but the documentation is unclear.
I've already tried many suggestions and hacks from StackOverflow and Google, but a lot are old (6+ years) and don't appear to be relevant to the current version. Here are some threads I've looked through:
Repeats Documentation
Multiple File Upload Widgets on the same page - main.js
Not answered, for a different version, or very old (or a combination of the three)
Two jQuery File Upload widgets on the same page
jQuery File Upload - Multiple File Upload Widgets on the same page
Multiple jQuery File Upload widgets on the same page
blueimp jQuery File Upload Multiple Instance
The documentation is here, which appears to be outdated
https://github.com/blueimp/jQuery-File-Upload/wiki/Multiple-File-Upload-Widgets-on-the-same-page
In main.js it suggests replacing:
$('#fileupload').fileupload();
With:
$('.fileupload').each(function () {
$(this).fileupload({
dropZone: $(this)
});
});
And modifying the form to change:
id="fileupload"
to:
class="fileupload"
But if you look at the current main.js file the line it suggests replacing is not present: https://github.com/blueimp/jQuery-File-Upload/blob/master/js/main.js
Here's my current (none working) code:
Form:
<form class="fileupload" action="upload.cgi" method="POST" enctype="multipart/form-data">
main.js:
$('.fileupload').each(function () {
$(this).fileupload({
dropZone: $(this)
})
});
'use strict';
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
url: '/upload.cgi'
});
// Enable iframe cross-domain access via redirect option:
$('#fileupload').fileupload(
'option',
'redirect',
window.location.href.replace(
/\/[^\/]*$/,
'/cors/result.html?%s'
)
);
I've replaced combinations of lines 14, 18 and 25 and tried as many ways as I can think of, but it either doesn't work, or doesn't work and produces errors, usually either TypeError: document.getElementById(...) is null or [object Object] not found.
I'm no expert in Javascript or jQuery which is why I tried to use this plugin in the first place. Could somebody please explain how main.js should actually look to handle multiple forms, because either the documentation is out of date (2012) or my understanding of them is flawed. Thank you.