FormPanel reset

109 views
Skip to first unread message

hovan

unread,
Aug 23, 2006, 6:58:34 PM8/23/06
to Google Web Toolkit
Hi All,

Is there any way to reset a FormPanel? any simple implement to call
form.reset() likes form.submit()?

Thanks,
hovan

hoosie

unread,
Aug 23, 2006, 7:05:37 PM8/23/06
to Google Web Toolkit
> Is there any way to reset a FormPanel? any simple implement to call
> form.reset() likes form.submit()?

Not built in. I do this:

First declare a hash of all fields:
private HashMap fields = new HashMap();

For each field (for example):

tb = new AZTextBox();
tb.setName("description");
tb.setVisibleLength(40);
somePanel.add(tb);
fields.put("description", tb);
...
...
as long as each field is referenced in the hash, the following reset
code works:

public void resetForm() {
Iterator iter = fields.values().iterator();
while (iter.hasNext()) {
// Get value
TextBoxBase tb = (TextBoxBase)iter.next();
tb.setText("");
}
}

Jason Essington

unread,
Aug 23, 2006, 7:10:04 PM8/23/06
to Google-We...@googlegroups.com
sure, I have some extra button widgets based upon the input element
rather than the button element.

public class FormButtonBase extends ButtonBase
{
static native void click(Element button) /*-{
button.click();
}-*/;

protected FormButtonBase()
{
super(DOM.createElement("input"));
}

public void click() {
click(getElement());
}
}


and

public class ResetButton extends FormButtonBase
{

public ResetButton()
{
super();
DOM.setAttribute(getElement(), "type", "reset");
}
public ResetButton(ClickListener listener)
{
this();
addClickListener(listener);
}

public ResetButton(String value)
{
this();
DOM.setAttribute(getElement(), "value", value);
}

public ResetButton(String value, ClickListener listener)
{
this(value);
addClickListener(listener);
}

}


it is also a simple matter to make a Submit button <input
type='submit'>,
and just a regular form button <input type='button'>


you can still add click listeners if you want, or simply let the
browser do its default reset thing.

-jason

hovan

unread,
Aug 24, 2006, 1:31:21 AM8/24/06
to Google Web Toolkit
Thanks,

Problem is, i have a form which has a FileUpload field. What i like to
do is: after complete the upload i am automatically reset the form.
That while i love to have something like form.reset() to call.

There is noway to reset the FileUpload field as i don;t see any method
do that. Is there any better way?

hovan.

hoosie

unread,
Aug 24, 2006, 2:01:15 AM8/24/06
to Google Web Toolkit
Recreate the Form object after the upload completes. Something like
myFormPanel blah = new myFormPanel(); and then reset the widget
wherever you've placed it.

hovan

unread,
Aug 28, 2006, 4:06:36 PM8/28/06
to Google Web Toolkit
This is form reset solution i modified from Google submit. It works
for me on both FF & IE.
Extends FormPanel and add the methods:

public void reset() {
//form, iframe
reset(getElement(), DOM.getFirstChild(getElement()));
}
/**
* Reset a form, this code is copy from FormPanelImpl of google
*
* @param form the form to be submitted
* @param iframe the iframe that is targetted, or <code>null</code>
*/
private native void reset(Element form, Element iframe) /*-{
// Hang on to the form's action url, needed in the
// onload/onreadystatechange handler.
if (iframe)
iframe.__formAction = form.action;
form.reset();
}-*/;

Pullu

unread,
Sep 3, 2012, 5:41:11 AM9/3/12
to google-we...@googlegroups.com, Google Web Toolkit

use fileUploadWidget.getElement().setPropertyString("value", ""); when SubmitCompleteEvent is called.

@UiHandler("uploadFileFormPanel") void handleuploadFileFormPanelSubmitComplete(SubmitCompleteEvent e){ uploadFile.getElement().setPropertyString("value", ""); presenter.uploadCompleted(e); }

Reply all
Reply to author
Forward
0 new messages