Skip to content

Commit

Permalink
Fix #40: Fix IE inability to clear fileinput values
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Oct 13, 2014
1 parent f88e690 commit 7a9161d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version 2.5.0
- (bug #37): HTML encode text content for preview in modal.
- (enh #38): Highlight error CSS in file caption on validation error.
- (bug #39): HTML encode caption hover title.
- (bug #40): Fix IE (ver < 11) inability to clear fileinput values.

version 2.4.0
=============
Expand Down
19 changes: 15 additions & 4 deletions js/fileinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
self.clear(false);
$cap.focus();
});
$($el[0].form).on('reset', $.proxy(self.reset, self));
$el.closest('form').on('reset', $.proxy(self.reset, self));
self.$container.on('click', '.fileinput-remove:not([disabled])', $.proxy(self.clear, self));
},
refresh: function (options) {
Expand Down Expand Up @@ -341,16 +341,27 @@
$(this).remove();
});
},
clear: function (e) {
var self = this;
clearFileInput: function() {
var self = this, $el = self.$element;
// Fix for IE ver < 11, that does not clear file inputs
if (/MSIE/.test(navigator.userAgent)) {
$el.wrap('<form>').closest('form').trigger('reset');
$el.unwrap();
} else {
$el.val('');
}
},
clear: function () {
var self = this, e = arguments.length && arguments[0];
if (e) {
e.preventDefault();
}
if (self.reader instanceof FileReader) {
self.reader.abort();
}
self.$element.val('');
self.clearFileInput();
self.resetErrors(true);

if (e !== false) {
self.$element.trigger('change');
self.$element.trigger('fileclear');
Expand Down
Loading

0 comments on commit 7a9161d

Please sign in to comment.