Dropzone autoProcessQueue: false not working

夙愿已清 提交于 2019-12-24 01:29:37

问题


I'm trying to upload files on button click.

I have followed so much tutorials/questions like, Upload all files with a button, Dropzone.js post request in laravel 5.4. But didn't get success.

This is my view file code,

<form action="{{ url('admin/candidate/file-upload') }}" method="post" class="dropzone" id="my-dropzone">
    {{ csrf_field() }}
    <div class="dz-message">
        <h3>Drop images here or click to upload.</h3>
    </div>
</form>

And this is my JS file code (in document ready block),

//DropZone - Drag and drop file upload
Dropzone.options.myDropzone = {
    // Prevents Dropzone from uploading dropped files immediately
    autoProcessQueue: false,

    init: function () {
        var submitButton = document.querySelector("#submit-all")
        myDropzone = this; // closure

        submitButton.addEventListener("click", function () {
            myDropzone.processQueue(); // Tell Dropzone to process all queued files.
        });
        // You might want to show the submit button only when 
        // files are dropped here:
        this.on("addedfile", function () {
            // Show submit button here and/or inform user to click it.
        });
    }
};

But I think my this js file block is not executing. What should be the problem?


回答1:


I fall at the same situation and found out that code:

Dropzone.options.myDropzone = { .. }

does nothink useful. Instead I use:

Dropzone.forElement(".dropzone").options.autoProcessQueue = false;

and after, when i need to queue i do:

Dropzone.forElement(".dropzone").processQueue();



回答2:


This did not work:

$(function(){ Dropzone.options.myDropzone = {...} }

This worked:

Dropzone.options.myDropzone = {...}

...as long as it was executed before the DOM loaded.



来源:https://stackoverflow.com/questions/43936018/dropzone-autoprocessqueue-false-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!