简体   繁体   中英

Require at least one file upload using plupload

I am trying to find a way to make it mandatory that at least one file is uploaded when using plupload ( https://www.plupload.com/ ) inside a form.

I do not see any options in plupload to require a file to be uploaded but, as plupload is not using a form field, I cannot use jQuery validate or HTML input required attribute which I am using on other form fields meaning the user can submit the form even if they have forgotten to upload a file.

I do not want the form to be submitted without at least one file being uploaded - I can check for this easily server side but I want to do this client side as well to improve the UX if possible.

Is it possible to make plupload work in this way?

Yes, there is way to implement this.

You can do something like this:

$("#upload-form").on('submit', function (e) {
    if (uploader.files.length > 0) {
        return true;
    }
    return false;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM