简体   繁体   中英

jQuery Blueimp fileupload plugin delete files without requiring checking checkbox first?

I can't figure out how to modify the jQuery Blueimp fileupload plugin jquery.fileupload-ui.js such that the delete button just deletes the files without having to check the checkbox first.

Might someone help me figure out how to do this?

here's the jquery.fileupload-ui.js code which appears to need some kind of modification:

 fileUploadButtonBar.find('.delete')
            .bind('click.' + ns, function (e) {
                e.preventDefault();
                filesList.find('.delete input:checked')
                    .siblings('button').click();
                fileUploadButtonBar.find('.toggle')
                    .prop('checked', false);
            });
        fileUploadButtonBar.find('.toggle')
            .bind('change.' + ns, function (e) {
                filesList.find('.delete input').prop(
                    'checked',
                    $(this).is(':checked')
                );
            });

I came across with the same problem and the solution is quite simpler.

1.You have to remove from the html all the input checkboxes.
2.Add a class to the delete all button(i used deleteAll).
3.Each delete button has a class="delete" so..
4.Activate that button for each row, when click the top Delete button.

//delete all photos when click top Delete all button
$('.deleteAll').click(function(){
  $('.delete').each(function(){
    $(this).click();
  });
});

Ok I fixed my own problem. The solution is just to have the checkboxes attribute set to checked="checked" in the template and HTML before these elements are rendered. Trying to check the checkboxes with Javascript clicking on the button wasn't working for me probably having to do with the call stack.

Anyway, here's the code. In the template-download instead of this:

<input type="checkbox" name="delete" value="1">

do this:

<input type="checkbox" name="delete" value="1" checked="checked">

and for the checkbox next to the delete button in the fileuploadBar , instead of this:

<input type="checkbox" class="toggle">

do this:

<input type="checkbox" class="toggle" checked="checked">

If you do this, then clicking any of the delete buttons will delete the file(s) (ie, one step instead of two).

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