JQuery: fileupload is not a function

Viewed 14

Good day everyone. I have the following problem:

I need to check if the form with input (type is file) is ready to submit (file upload must be completed). I tried to check if the file is uploaded by JQuery function: fileupload('active'), but I received this error: Uncaught TypeError: fileInput.fileupload is not a function.

The code is here:

for (let i = 0; i < fileForms.length; i++) {
    var subFormInput = document.createElement("input");
    subFormInput.setAttribute("type", "hidden");
    subFormInput.setAttribute("name", "submittedFormId");
    subFormInput.setAttribute("value", response.submittedFormId);
    fileForms[i].appendChild(subFormInput);
    i=0;
    fileInput = fileForms[i].querySelector('input[name="answer"]');
    console.log(fileInput);
    while (fileInput.fileupload('active') > 0) {
        i++;
    }
    fileForms[i].submit();
}
1 Answers

I solved problem by using FileReader.

for (let i = 0; i < fileForms.length; i++) {
    var subFormInput = document.createElement("input");
    subFormInput.setAttribute("type", "hidden");
    subFormInput.setAttribute("name", "submittedFormId");
    subFormInput.setAttribute("value", response.submittedFormId);
    fileForms[i].appendChild(subFormInput);
    fileInput = fileForms[i].querySelector('input[name="answer"]');
    if (fileInput.value != "") {
        const reader = new FileReader();
        const file = fileInput.files[0];
        reader.readAsArrayBuffer(file);
        reader.onload = function () {
            fileForms[i].submit();
            console.log("file is ready");
        };
    } else {
        fileForms[i].submit();
    }
}
Related