Repository navigation
Multiple plugin instances on the same page
blueimp edited this page Aug 16, 2011
·
11 revisions
Note: This tutorial is for the outdated v4 branch of the plugin.
Multiple File Upload Forms on the same webpage are supported out of the box and don't need any additional Options.
Here is a sample HTML code with two file upload forms on the same page:
<form class="file_upload" action="upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file" multiple>
<button>Upload</button>
<div>Upload files</div>
</form>
<form class="file_upload" action="upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file" multiple>
<button>Upload</button>
<div>Upload files</div>
</form>
<table id="files"></table>And the associated plugin initialization:
/*global $ */
$(function () {
$('.file_upload').fileUploadUI({
uploadTable: $('#files'),
buildUploadRow: function (files, index) {
return $('<tr><td>' + files[index].name + '<\/td>' +
'<td class="file_upload_progress"><div><\/div><\/td>' +
'<td class="file_upload_cancel">' +
'<button class="ui-state-default ui-corner-all" title="Cancel">' +
'<span class="ui-icon ui-icon-cancel">Cancel<\/span>' +
'<\/button><\/td><\/tr>');
},
buildDownloadRow: function (file) {
return $('<tr><td>' + file.name + '<\/td><\/tr>');
}
});
});Note that the plugin initialization does not differ from the basic Setup.
The only difference is the jQuery selector, applying the plugin call to both forms.