0

I'm using a function from here on SO to reset a file input element.

<input type="file" id="image-file" />

JS:

function resetFormElement(e) {
    e.wrap('<form>').closest('form').get(0).reset();
    e.unwrap();
    e.stopPropagation();
    e.preventDefault();
 }

resetFormElement($('#image-file'));

Resetting it seems to work but it gives the type error for stopPropagation() and preventDefault() in the console

frosty
  • 2,779
  • 6
  • 34
  • 63
  • What would you be stopping the propagation of anyways, here? – StackSlave Jun 14 '16 at 22:36
  • Why are you calling those? They don't really make sense on an element. –  Jun 14 '16 at 22:37
  • Well, yeah. You're passing it a jQuery object (`$('#image-file')`). `stopPropagation` and `preventDefault` are on event objects, like what you would get during a click event. – Mike Cluck Jun 14 '16 at 22:37
  • I assume you got that code [from here](http://stackoverflow.com/a/13351234/1106925). Just FYI, there's no obligation to use the highest ranked answer. If one doesn't work, try another. There are 25 answers on that page. –  Jun 14 '16 at 22:44

1 Answers1

1

https://developer.mozilla.org/en/docs/Web/API/Event/stopPropagation

You function looks like handler for UI event, so it wait that event-object will be passed as arguments

But when you call it manually -- it doesn't. If it is the only way you use the function - just remove redundant calls

function resetFormElement(e) {
    e.wrap('<form>').closest('form').get(0).reset();
    e.unwrap();
 }
Vasiliy vvscode Vanchuk
  • 7,007
  • 2
  • 21
  • 44