Bug Tracker

Opened 6 years ago

Closed 6 years ago

#12917 closed bug (plugin)

input type[file] can't be reset with val('') in IE (+ workaround)

Reported by: matthew@… Owned by:
Priority: low Milestone: None
Component: attributes Version: 1.8.3
Keywords: Cc:
Blocked by: Blocking:

Description

Due to IE's inane security manager, you can't set the value of an input[file], even to "" to reset it.

There's a workaround that might be useful to pull into jQuery. It wraps a form around the input element, calls reset on it, then removes the parent element:

http://stackoverflow.com/questions/1043957/clearing-input-type-file-using-jquery/13351234#13351234

function reset(e) {

e.wrap('<form>').closest('form').get(0).reset(); e.unwrap();

}​

This workaround works in all browsers:

http://jsfiddle.net/rPaZQ/

Change History (1)

comment:1 Changed 6 years ago by timmywil

Component: unfiledattributes
Priority: undecidedlow
Resolution: plugin
Status: newclosed

Sounds like this would be good for a jQuery plugin like file upload.

Note: See TracTickets for help on using tickets.