开发者

Trying to manually remove a file from Multifile upload

开发者 https://www.devze.com 2023-02-18 22:18 出处:网络
I\'m using jQuery Multiple File Upload Plugin and I have the following: $(function(){ // wait for document to load

I'm using jQuery Multiple File Upload Plugin and I have the following:

$(function(){ // wait for document to load
    $('#attachFiles').MultiFile({
        list: '#attList',
        STRING: { remove: '<img src="cross.gif" title="Remove this attachment" border="0">' },
        afterFileAppend: function(element, value, master_element) {
            $(".amount").each(function(){
                var i       = $(this).attr("i");
                var curVal  = $("#attachment_" + i).val();
                if($("#attachment_" + i).is(":checked") && curVal == "X") {
                    $("#attachment_" + i).attr("value", value);
                    $("#attachment_" + i).attr("title", "Attachment " + value + " linked");
                    aCounter++;
                };
            });
            if(aCounter==0) {
        开发者_如何学JAVA        alert("You need to select...");
                //Remove should be here
            }
        }
    });
});

If I add a file named test.pdf then one named test2.pdf my goal is to automatically remove test2.pdf if my aCounter variable is 0 (that would mean the user did not check off any additional check boxes named attachment_#.

I can't seem to figure out how to remove just the file that was added. If I understand correctly, the value of the file that I add gets added to id="attachfiles" which is a

<input type="file" name="userfile[]" id="attachFiles" class="file" size="1" accept="pdf|jpg|jpeg">

So I'm assuming I should be able to somehow remove the most recently added item somehow. Any assistance or guidance would be great.


The jQuery Multiple File plugins that I've used do NOT use some array to hold the set of files. They use a series of

<input type="file" ... style="position:absolute; left:-3000px;" /> 
<input type="file" ... style="position:absolute; left:-3000px;" />

elements that are hidden after the user selects a file. The displayed input element is replaced with a new one. This also seems to be the case with your plugin. You should be able to find the most recent file by doing some selector

$("#mydiv input[type='file']").last()

or something similar and removing it from the DOM.

You can probably also do a trigger('click') on the appropriate delete button.

0

精彩评论

暂无评论...
验证码 换一张
取 消