However it works, it does so rather badly; when I looked at this page,
the text box first appeared briefly and then vanished; and when I
pressed 'Reload', it came back again...
This is with a completely vanilla Firefox 3b5 on Windows, too.
--
David Given
d...@cowlark.com
As said previously: put the FileUpload widget as a hidden element.
Then add a button or link on your page with an onclick listener that
calls JSNI code:
final FileUpload upload = new FileUpload();
upload.setName("uploadFormElement");
panel.add(upload);
panel.add( new Button("Select File", new ClickListener() {
public void onClick(Widget pSender) {
jsClickUpload( upload.getElement() );
}
}));
where jsClickUpload is something similar to:
native void jsClickUpload( Element pElement ) /*-{
pElement.click();
}-*/;
I don't know if this is supported in all Browsers, there must be
similar solutions since GMail is capable of doing this.
I tried this on IE6 and it works. I guess there are similar things
available in FireFox or Safari/WebKit.
Of course you lose the possibility of drag and drop of files as
supported in Safari.
It would be a nice addition that we can trigger the File dialog in the
standard FileUpload widget (depending on the browser type).
David
Browsers do not support you to set the filename from javascript, that
would be a security problem.
But what you can do, is just remove the FileUpload widget from the
form and add a new one every time you want to add a file to the
upload.
David
Call form.reset() from JSNI.
But then you will reset everything not just the Filename,
David