Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fileuploadederror triggered twice times if two uploaded files uploaded before #1014

Closed
mgjun opened this issue Jul 15, 2017 · 7 comments
Closed

Comments

@mgjun
Copy link

mgjun commented Jul 15, 2017

upload file in a modal,first time upload two files to server,then reopen the modal,upload a invalid file,the fileuploadederror will trigger twice.

@mgjun
Copy link
Author

mgjun commented Jul 15, 2017

if three file uploaded to server before,next time select a invalid file,the fileuploadederror will trigger three times.why this?

@mgjun
Copy link
Author

mgjun commented Jul 15, 2017

fileInput:{
$el:null,
fileCounts:0,
frameHeight:'145px',
default_options:{
uploadAsync: false,
showCaption: false,
showUpload: false,
showCancel: false,
showClose: false,
showRemove: false,
showBrowse: false,
showUploadedThumbs: false,
captionClass: "col-sm-6",
allowedFileTypes: ['image'],
allowedFileExtensions: ['jpg', 'png', 'gif'],
maxFileSize: 10*1024,
minFileCount: 1,
maxFileCount: 5
},
display_options:{
dropZoneTitleClass:"hide"
},
edit_options:{
showPreview:true,
showUploadedThumbs: true,
dragClass:"hide",
showDrag:false,
dropZoneTitle:'drop or browse',
removeFromPreviewOnError:true,
overwriteInitial: false,
elErrorContainer:'hide',
previewSettings: {
image: {width: "auto", height: "60px"},
html: {width: "50px", height: "40px"},
text: {width: "50px", height: "40px"},
video: {width: "50px", height: "40px"},
audio: {width: "50px", height: "40px"},
flash: {width: "50px", height: "40px"},
object: {width: "50px", height: "auto"},
pdf: {width: "50px", height: "40px"},
other: {width: "50px", height: "40px"}
}
},
init:function ($el, options, editable) {
var _this = this;
_this.$el = $el;
var ops;
ops = editable ? $.extend({},_this.default_options,_this.edit_options) : $.extend({},_this.default_options,_this.display_options);
$el.fileinput($.extend({},ops,options));

        if(editable) {
            $(".file-drop-zone").css("min-height",_this.frameHeight);
            $el.on("filedeleted",function () {
                appOption.fileInput.fileCounts--;
                if(appOption.fileInput.fileCounts <= 0) {
                    appOption.fileInput.destroy($el).init($el,options,editable);
                }
            }).on("fileremoved",function () {
                appOption.fileInput.fileCounts--;
                if(appOption.fileInput.fileCounts <= 0) {
                    appOption.fileInput.destroy($el).init($el,options,editable);
                }
            }).on("filebatchselected",function (event, files) {
                if(files) appOption.fileInput.fileCounts += files.length;
            }).on("fileuploaderror",function (event, data, msg) {
                toastr.options.timeOut = 20000;
                toastr.error(msg);
            }).on("change",function () {
                // _this.$el.val("");
            });
        }
    },
    triggerUpload:function () {
        this.$el.val("");
        return this.$el.trigger("click");
    },
    destroy:function ($el) {
        $el.fileinput("destroy");
        return this;
    },
    upload:function ($el) {
        $el.fileinput("upload");
        return this;
    },
    refresh:function ($el, options) {
        if(isEmpty(options)) {
            $el.fileinput("refresh");
        }else {
            $el.fileinput("refresh",options);
        }
        return this;
    },
    progressSuccess:function () {
        $(".file-input").find(".progress").html('<div class="text-center back-main color-white">success</div>');
        $(".file-preview-loading").removeClass("file-preview-loading");
        $(".file-uploading").removeClass("file-uploading");
    },
    progressFailure:function () {
        $(".file-input").find(".progress").html('<div class="text-center back-error color-white">error</div>');
        $(".file-preview-loading").removeClass("file-preview-loading");
        $(".file-uploading").removeClass("file-uploading");
    }
},

@erick-x
Copy link

erick-x commented Jul 20, 2017

same question ,you can change on to one trigger only once . probably,it`s bug for trigger event.

@mgjun
Copy link
Author

mgjun commented Jul 20, 2017 via email

@rapgithub
Copy link

how do you use $el.fileinput("refresh"); ? because I am having problems to refresh the content with ajax... see this link maybe you know what is the problem is:

here
#1028

@kartik-v
Copy link
Owner

kartik-v commented Jul 29, 2017

@mj3018 It seems some problem the way you are writing your code. Cross check as cannot reproduce this.

Anyway there are some related enhancements added as well to file upload single method currently.

@rapgithub
Copy link

rapgithub commented Jul 30, 2017

Any news about the problem of refreshing the images with ajax calls properly like in my link i provided and no news about it:

https://www.dropbox.com/s/ugwhk09apy99fag/github-fileinput-issue.mov?dl=0

can you provide where did you cross check this issue with ajax maybe in codepen.io because in my case all the check produce the same issue all the time...

Images not being refreshing dynamically when requested via ajax...
thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants