Skip to content

oetiker/UploadWidget

Repository files navigation

UploadWidget

Copyright:

License:

  • MIT
  • See the LICENSE file in the project's top-level directory for details.

Authors:

  • Dietrich Streifert (level420)
  • Petr Kobalicek (e666e)
  • Tobi Oetiker (oetiker)

UploadForm and UploadFile Implementation.

The class UploadForm creates a hidden iframe which is used as a target for the form submit.

An event of type "sending" is fired after submit. On completion (iframe completed loading) a "completed" event is fired.

UploadForm implements the methods getIframeTextContent(), getIframeHtmlContent() and getIframeXmlContent() to get the content of the iframe.

UploadFile fires a "changeValue" event after the selection by the OS file selector is completed.

Multiple UploadFile instances are possible. The text field is read-only.

I think that "POST" and "multipart/form-data" only is not really limitation. I never used something else in my life. Enjoy this port!

Example:

var form, upload;

form = new uploadwidget.UploadForm("upload", "/url/");
form.setLayout(new qx.ui.layout.HBox());
form.addListener("completed", function(e) 
{ 
  alert("complete");
});

upload = new uploadwidget.UploadButton("file", "Upload", "/yourIcon.png");
upload.addListener("changeFileName", function(e)
{
  if (e.getData() != "") form.send();
});
form.add(upload);

Example how add UploadButton to toolbar:

var upload;

upload = new uploadwidget.UploadButton("file", "Upload", "/yourIcon.png");
upload.set({appearance : "toolbar-button"});