The way I limited it to single file, was to create js file and attach it to the form. In that file, I bound a function to QueueChanged
, to remove excess files and hide "Add file" button:
(function($) {
Drupal.plupload = Drupal.plupload || {};
/**
* Attaches the Plupload behavior to each Plupload form element.
*/
Drupal.behaviors.download_plupload = {
attach: function (context, settings) {
$(".plupload-element", context).once('download-plupload-init', function () {
var add_button = $(this).find('.plupload_button.plupload_add');
var uploader = $(this).pluploadQueue();
uploader.bind('QueueChanged', function() {
var local_uploader_element = this;
// Remove files exceeding the cardinality setting.
if (local_uploader_element.files.length >= 1) {
var i = 0;
for (i=0;i<local_uploader_element.files.length;i++) {
if (i >= 1) {
$(this).removeFile(uploader.files[i]);
}
}
add_button.hide();
}
else {
add_button.show();
}
});
});
}
};
})(jQuery);
This is a simplified version of js found in FileField Sources Plupload, trimmed, without Field API specific parts, and made to work on all plupload elements.