Is there any way to reset a FormPanel? any simple implement to call
form.reset() likes form.submit()?
Thanks,
hovan
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("");
}
}
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
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.
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();
}-*/;
use fileUploadWidget.getElement().setPropertyString("value", ""); when SubmitCompleteEvent is called.
@UiHandler("uploadFileFormPanel")
void handleuploadFileFormPanelSubmitComplete(SubmitCompleteEvent e){
uploadFile.getElement().setPropertyString("value", "");
presenter.uploadCompleted(e);
}