Jquery - FileUploader can delete file but is submitted in the same

0

Good people,

I'm using the following Jquey plugin to upload files:

I intend, in addition to submitting files, it allows the user to be able to delete those same files before submitting them.

I'm using the following code:

$('#fileupload').fileupload({

                dataType: "json",
                url: "Handler.ashx?alp=0&bostamp=" + bostamp,
                limitConcurrentUploads: 1,
                sequentialUploads: true,
                progressInterval: 100,
                maxChunkSize: 17179869184,
                maxFileSize: 17179869184,


                add: function (e, data) {
                    var code = data.files[0].name;
                    var mlen = data.files[0].size;
                    var ftype = data.files[0].type;
                    var oktype = 'ok';
                    switch (ftype) {
                        case 'image/jpeg':
                            {
                                oktype = 'ok';
                                break;
                            }
                        case 'image/pjpeg':
                            {
                                oktype = 'ok';
                                break;
                            }
                        default:
                            {
                                oktype = 'nok';
                                break;
                            }
                    }
                    //limita tipo de ficheiro jpeg
                    if (oktype == 'nok') {
                        var opts = {
                            "closeButton": true,
                            "debug": false,
                            "positionClass": "toast-top-right",
                            "onclick": null,
                            "showDuration": "300",
                            "hideDuration": "1000",
                            "timeOut": "5000",
                            "extendedTimeOut": "1000",
                            "showEasing": "swing",
                            "hideEasing": "linear",
                            "showMethod": "fadeIn",
                            "hideMethod": "fadeOut"
                        };

                        toastr.error(code + ' ' + $('#lblerrformato').val(), "UPLOAD ERROR", opts);
                        //alert(code+' Unsupported File!');
                    } else {
                        //limita a 20MB por ficheiro 20971520

                        if (parseInt(mlen) > 52428800) {
                            var opts = {
                                "closeButton": true,
                                "debug": false,
                                "positionClass": "toast-top-right",
                                "onclick": null,
                                "showDuration": "300",
                                "hideDuration": "1000",
                                "timeOut": "5000",
                                "extendedTimeOut": "1000",
                                "showEasing": "swing",
                                "hideEasing": "linear",
                                "showMethod": "fadeIn",
                                "hideMethod": "fadeOut"
                            };

                            toastr.error(code + ' ' + $('#lblerrtamanho').val(), "UPLOAD ERROR", opts);
                            //alert(code+' ultrapassa o tamanho permitido.');
                        } else {
                            var maxse = $('#ctl00_hidseq').val();
                            //alert(maxse);
                            $('#filelistcontent').removeClass('hide');
                            $('#progress-holder').removeClass('hide');
                            data.context = $('<div />').text(data.files[0].name).appendTo('#filelistholder');
                            $('</div><div class="progress"><div class="progress-bar" style="width:0%"></div></div>').appendTo(data.context);

                            //novo codigo para apagar os ficheiros em espera quando necessario
                            $.each(data.files, function (index, file) {
                                $('</div> - <a href="#" class="deleteUpload"><span class="glyphicon glyphicon-trash" aria-hidden="true" style="font-size: 15px; margin-left:20px;"></span></a><hr>').appendTo(data.context);
                                console.log(index);
                                $('.deleteUpload').click(function () {
                                    $(this).parent().remove();
                                    $('#fileupload')
                                    if ($('#filelistholder').html() == "") {
                                        $('#filelistcontent').addClass('hide');
                                    }
                                });

                            });
                            $('#ctl00_btnUploadAll').click(function () {
                                data.submit();
                            });
                        }
                    }
                },
            });

With this code I can remove from DOM , but when submitting the files, the ones that were supposedly deleted, are also submitted.

Thanks in advance for the help.

    
asked by anonymous 23.10.2018 / 11:38

0 answers