jfeldstein / jQuery.AjaxFileUpload.js

jQuery plugin to magically make file inputs upload via ajax
408 stars 246 forks source link

How to call upload_file() on file input #27

Closed WojciechJasinski closed 11 years ago

WojciechJasinski commented 11 years ago

I've attached ajaxfileupload to my input#file1 and input#file2 with submit_button set to $('#fake_submit') because I don't want to upload file automatically. I would like to upload both files under some conditions for example:

$('#upload').on('click', function() {
    if(some_condition) {
        // force upload
        $('input#file1').upload_file(); // object has no method upload_file()
        $('input#file2').upload_file(); // object has no method upload_file()
    } else (some_other_condition) {
        $('input#file1').upload_file(); // object has no method upload_file()
    } else {
        $('input#file2').upload_file(); // object has no method upload_file()    
    }
});

Any ideas how to make it work?

jfeldstein commented 11 years ago

You might try binding both inputs to the same button (which you're already doing) and then additionally using the onStart handler to cancel one or the other inputs from uploading based on your extra logic.

An onStart handler which returns falls will cancel that input's upload.

Hope that helps!