Skip to content

Commit

Permalink
Fixed #254 - FileUpload in auto mode sends two post requests in IE11
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Apr 1, 2020
1 parent c51d545 commit 030f44f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/components/fileupload/FileUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default {
default: 'Cancel'
}
},
duplicateIEEvent: false,
data() {
return {
files: null,
Expand All @@ -108,6 +109,11 @@ export default {
},
methods: {
onFileSelect(event) {
if (event.type !== 'drop' && this.isIE11() && this.duplicateIEEvent) {
this.duplicateIEEvent = false;
return;
}
this.messages = [];
this.files = this.files || [];
let files = event.dataTransfer ? event.dataTransfer.files : event.target.files;
Expand All @@ -128,7 +134,10 @@ export default {
this.upload();
}
if (this.isAdvanced) {
if (event.type !== 'drop' && this.isIE11()) {
this.clearIEInput();
}
else {
this.clearInputElement();
}
},
Expand Down Expand Up @@ -213,6 +222,9 @@ export default {
return false;
},
isIE11() {
return !!window['MSInputMethodContext'] && !!document['documentMode'];
},
validate(file) {
if (this.maxFileSize && file.size > this.maxFileSize) {
this.messages.push(this.invalidFileSizeMessage.replace('{0}', file.name).replace('{1}', this.formatSize(this.maxFileSize)));
Expand Down Expand Up @@ -248,6 +260,12 @@ export default {
clearInputElement() {
this.$refs.fileInput.value = '';
},
clearIEInput() {
if (this.$refs.fileInput) {
this.duplicateIEEvent = true; //IE11 fix to prevent onFileChange trigger again
this.$refs.fileInput.value = '';
}
},
formatSize(bytes) {
if (bytes === 0) {
return '0 B';
Expand Down

0 comments on commit 030f44f

Please sign in to comment.