1

I need code snippet of django file upload form with single button. I've found excellent implementation of minimal-django-file-upload-example, but there are two buttons: "Browse" and "Upload". Is there a way to submit the file immediately after browsing without clicking "Upload" button?

Community
  • 1
  • 1
ivan.koval
  • 119
  • 2
  • 8

1 Answers1

2

Using JavaScript/jQuery:

<form>
    <input type="file" class="autosubmit" />
</form>

And then apply the following:

$('form .autosubmit').on('change', function() {
   this.form.submit();
});

Without jQuery it's very similar, you'll just need to use EventTarget.addEventListener.

DanielB
  • 2,798
  • 1
  • 19
  • 29