1

I have a form with fileupload.

<input class="file" type="file" name="files[]">

I am curently cloning the input, but if a file is choosen it also clones the choosen filinput, is there a way to clear the selected image?

script: $('.fieldset-content_doc').first().clone().appendTo('.fieldset-clone_doc').find('.file').reset();

fieldset-content_doc: holds the formvalues

sdfgg45
  • 1,232
  • 4
  • 22
  • 42

3 Answers3

1

Apparently the issue is only reproducible on Firefox. But, you can simply set the value property of the element to null:

$('.fieldset-content_doc')
    .first()
    .clone()
    .appendTo('.fieldset-clone_doc')
    .find('.file')
    .each(function() { this.value = null; });

See Fiddle

haim770
  • 48,394
  • 7
  • 105
  • 133
0

You can't use reset() if field is not inside <form>. You can clear input by wrapping element into form, reseting it and then unwrapping.

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

  // Prevent form submission
  e.stopPropagation();
  e.preventDefault();
}

See: https://stackoverflow.com/a/13351234/3581321

Community
  • 1
  • 1
MatiK
  • 573
  • 1
  • 7
  • 21
0

In your script instead of reset() you can use val(''). Like this

$('.fieldset-content_doc').first().clone().appendTo('.fieldset-clone_doc').find('.file').val('');