Maarten Hartman
Maarten Hartman

Reputation: 1629

jQuery, blueimp file upload: clear form only works onclick

I'm using the blueimp file upload plugin, everything is working fine so far. I have implemented this plugin into my own form, which is submitted through ajax, this is working well too.

Now the problem: after successful submission, I go back to the form, all input fields are cleared, except the file upload list.

this solution should work, and it does when I use in within an onclick function:

https://github.com/blueimp/jQuery-File-Upload/issues/1631

But I don't want to use a separate clear button, I want to clear the form + file list after successful submission, so logically, I wrote this code:

 success: function(response) {
  // on success
  if (response.success === 1) {
    $('#fileupload table tbody tr.template-download').remove();

but this doesn't work, even when I just put the line on top, below document.ready (so clear onload).

Why does this only work onclick? Am I missing something? Any suggestions?

Thanks in advance for your assistance

Upvotes: 2

Views: 7574

Answers (4)

Ray Cheung
Ray Cheung

Reputation: 21

None of the solution posted before worked for me. But unbinding the upload button did the trick.

progressall: function (e, data) {
  var progress = parseInt(data.loaded / data.total * 100, 10);
  if(progress==100)
    {  
      $('#btnUploadAll').unbind('click');
    }
}

Upvotes: 1

MonkeyBlue
MonkeyBlue

Reputation: 2234

Try calling this, this worked for me

$("#fileupload").find(".files").empty();

Upvotes: 6

user2009117
user2009117

Reputation: 61

just have a look at option "replaceFileInput". I had the same problem and after adding this option with value "false" to the jquery file upload plugin it works for me.

Seems that jquery file upload is a little bit tricky at this point and during replacement of the input field behind the scene, inmportant event signups will get lost.

Don't know if its a bug or a feature. :)

Regards

Udo

Upvotes: 0

CtrlX
CtrlX

Reputation: 7015

Do you have tried to put it on the done (instead of success) :

 $('#fileupload').fileupload({
        url: url,
        dataType: 'json',
        done: function (e, data) {
                 $('#fileupload table tbody tr.template-download').remove();
            }
        });

Upvotes: 0

Related Questions