Hi,

I would like to refer to this issue https://drupal.org/node/1804382 and particularly comment #32

I want to remove the "Start upload" button and make the uploading process start automatically as soon as the image files have been selected.

For a while I tinkered with "Plupload integration" module to get this to work, and while it works for others in that thread,it didn't work for me. It turns out that this is because FileField Sources Plupload has it's own plupload.js

Could you PLEASE provide the customisation code for the auto-upload functionality?

Many thanks

Comments

betoaveiga’s picture

Hi Drupalina! I did a script that you can include whenever you need "autoupload" functionality...

(function ($) {    
    $(document).ready (function () {
        // Here goes the selector of the button that starts the upload
        var startUploadButtonClass = '.filefield-source-plupload button[type=submit]';
        var checkForNewFilesInterval = 1000;
        // This line could go in your CSS
        $('head').append('<style>'+ startUploadButtonClass +'{ display:none } </style>');
        // Checking every checkForNewFilesInterval seconds
        setInterval (function () {
            var $pluploadFilelist = $('.plupload .plupload_filelist li');
            var filesToUpload = $pluploadFilelist.length;
            if (filesToUpload>0) {
                $(startUploadButtonClass).click(); 
            }
        },checkForNewFilesInterval);
    });    
}(jQuery));

Hope that helps!

modstore’s picture

Issue summary: View changes

Thanks BetoAveiga,

I just added this code and it works nicely.

nwom’s picture

I added the js file to my site, but it doesn't seem to autohide the button, or autoupload the files. How did you guys go about implementing the code on the site? Thanks in advanced.

nwom’s picture

Nevermind. Thanks so much for the script. I changed:

var startUploadButtonClass = '.filefield-source-plupload button[type=submit]';

to

var startUploadButtonClass = '.filefield-source-plupload input[type=submit]';

and then it worked.

scotty’s picture

Thanks, #1 with the change from #4 works great. Really improves the UX.

betoaveiga’s picture

@NWOM sorry I didn't read your comments before :/
@scotty & @modstore I'm glad to help :)

cthshabel’s picture

The script that BetoAveiga wrote is nice; however, what about situations where the user wants also "autosubmit" also? Something more like the patch posted here in the same issue queue (Comment #36) Drupalina posted: https://drupal.org/node/1804382

User only wants to upload one single image. So once it is there, the submit button is also triggered to open up image preview.

Steve Bizuns’s picture

#1 combined with #4 worked great. You guys are my heroes today.

Chipie’s picture

Issue summary: View changes
StatusFileSize
new30.02 KB

I have tried the script and it works fine, when uploading a file. But when I create a node without a file, the node is not saved. It reloads the form with two plupload widgets:

Anyone having the same issue?

modstore’s picture

Check if you have any js errors in your browser console.

Chipie’s picture

I have solved it by using an event instead of timer:

(function($) {
    $(document).ready (function () {
            // automatic upload files when added to plupload
            // hide upload button
            var startUploadButtonClass = '.filefield-source-plupload input[type=submit]';
            $('head').append('<style>'+ startUploadButtonClass +'{ display:none } </style>');
            $(".plupload-element").once('mymodule-plupload-init', function () {
                var uploader = $(this).pluploadQueue();
                if(uploader !== undefined) {
                    uploader.bind('FilesAdded', function(up, files) {
                        $(startUploadButtonClass).click();
                        $('.form-submit').prop( "disabled", true );
                        //uploader.start();
                    });
                    uploader.bind('UploadComplete', function() {
                        if (uploader.files.length == (uploader.total.uploaded + uploader.total.failed)) {
                            // If nothing is being uploaded right now:
                            $('.form-submit').prop( "disabled", false );
                        }
                    });
                }
            });
    });
}(jQuery));
nwom’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Status: Active » Needs work

Any good way we can integrate this into the module as a setting? I can definitely see others benefiting from this feature as well.

nwom’s picture

It also appears #11 works with the first files that are either selected or dragged into the upload box. When trying to add additional files, they do not auto-upload. Due to this, I will revert back to the combination of #1 and #4.

nwom’s picture

Attached is a patch based on the combination of #1 and #4, since #11 had problems with adding files multiple times.

The patch automatically defaults to "auto-upload" for all plupload sources and is fully functional. It however still needs work, in order to make it optional instead. Any help would be greatly appreciated.

vaccinemedia’s picture

I've applied the patch and unfortunately the files are not auto uploaded. I have checked and the js file added by the patch is being added as is the style tag in the head which is also not hiding the start upload button. Is there not a way we can solve this as per the suggestion here?
https://drupal.stackexchange.com/questions/87033/how-can-i-make-plupload...