use of org.gwtproject.user.client.ui.FormPanel.SubmitCompleteHandler in project gwtproject by treblereel.
the class FormPanelTest method testFileUpload.
public void testFileUpload() {
final FormPanel form = new FormPanel();
form.setMethod(FormPanel.METHOD_POST);
form.setEncoding(FormPanel.ENCODING_MULTIPART);
assertEquals(FormPanel.ENCODING_MULTIPART, form.getEncoding());
form.setAction("formHandler");
FileUpload file = new FileUpload();
file.setName("file0");
form.setWidget(file);
RootPanel.get().add(form);
delayTestFinish(TEST_DELAY);
form.addSubmitCompleteHandler(new SubmitCompleteHandler() {
@Override
public void onSubmitComplete(SubmitCompleteEvent event) {
// The server just echoes the contents of the request. The following
// string should have been present in it.
assertTrue(event.getResults().indexOf("Content-Disposition: form-data; name=\"file0\";") != -1);
finishTest();
}
});
form.submit();
}
use of org.gwtproject.user.client.ui.FormPanel.SubmitCompleteHandler in project gwtproject by treblereel.
the class FormPanelTest method testWrappedFormWithIFrame.
public void testWrappedFormWithIFrame() {
// Create a form and frame in the document we can wrap.
final Element container = Document.get().createDivElement();
container.setInnerHTML("<form method='get' " + "encoding='application/x-www-form-urlencoded' action='" + "formHandler'>" + "<input type='text' name='tb' value='text'></input></form>");
Document.get().getBody().appendChild(container);
// Wrap the form, asking for an iframe to be created.
FormPanel form = FormPanel.wrap(container.getFirstChildElement(), true);
// Give the submit 5s to complete.
delayTestFinish(TEST_DELAY);
form.addSubmitCompleteHandler(new SubmitCompleteHandler() {
@Override
public void onSubmitComplete(SubmitCompleteEvent event) {
// Make sure we get our results back.
assertTrue(event.getResults().equals("tb=text"));
finishTest();
}
});
form.submit();
}
use of org.gwtproject.user.client.ui.FormPanel.SubmitCompleteHandler in project gwtproject by treblereel.
the class FormPanelTest method testCancelSubmit.
public void testCancelSubmit() {
TextBox tb = new TextBox();
tb.setName("q");
FormPanel form = new FormPanel();
form.setWidget(tb);
form.setAction("http://www.google.com/search");
form.addSubmitHandler(new SubmitHandler() {
@Override
public void onSubmit(SubmitEvent event) {
event.cancel();
}
});
form.addSubmitCompleteHandler(new SubmitCompleteHandler() {
@Override
public void onSubmitComplete(SubmitCompleteEvent event) {
fail("Form was canceled and should not have been submitted");
}
});
form.submit();
}
use of org.gwtproject.user.client.ui.FormPanel.SubmitCompleteHandler in project gwtproject by treblereel.
the class FormPanelTest method testMethodGet.
/**
* Tests submitting using url-encoded get, with all form widgets (other than
* FileUpload, which requires post/multipart.
*/
public void testMethodGet() {
final FormPanel form = new FormPanel();
form.setMethod(FormPanel.METHOD_GET);
form.setEncoding(FormPanel.ENCODING_URLENCODED);
form.setAction("formHandler");
TextBox tb = new TextBox();
tb.setText("text");
tb.setName("tb");
PasswordTextBox ptb = new PasswordTextBox();
ptb.setText("password");
ptb.setName("ptb");
CheckBox cb0 = new CheckBox(), cb1 = new CheckBox();
cb1.setValue(true);
cb0.setName("cb0");
cb1.setName("cb1");
RadioButton rb0 = new RadioButton("foo");
RadioButton rb1 = new RadioButton("foo");
rb0.setValue(true);
rb0.setName("rb0");
rb1.setName("rb1");
ListBox lb = new ListBox();
lb.addItem("option0");
lb.addItem("option1");
lb.addItem("option2");
lb.setValue(0, "value0");
lb.setValue(1, "value1");
lb.setValue(2, "value2");
lb.setSelectedIndex(1);
lb.setName("lb");
Hidden h = new Hidden("h", "v");
FlowPanel panel = new FlowPanel();
panel.add(tb);
panel.add(ptb);
panel.add(cb0);
panel.add(cb1);
panel.add(rb0);
panel.add(rb1);
panel.add(lb);
panel.add(h);
form.setWidget(panel);
RootPanel.get().add(form);
delayTestFinish(TEST_DELAY);
form.addSubmitCompleteHandler(new SubmitCompleteHandler() {
@Override
public void onSubmitComplete(SubmitCompleteEvent event) {
// The server just echoes the query string. This is what it should look
// like.
assertTrue(event.getResults().equals("tb=text&ptb=password&cb1=on&rb0=on&lb=value1&h=v"));
finishTest();
}
});
form.submit();
}
use of org.gwtproject.user.client.ui.FormPanel.SubmitCompleteHandler in project gwtproject by treblereel.
the class FormPanelTest method testSubmitAndHideDialog.
public void testSubmitAndHideDialog() {
final FormPanel form = new FormPanel();
form.setMethod(FormPanel.METHOD_GET);
form.setEncoding(FormPanel.ENCODING_URLENCODED);
form.setAction("formHandler");
TextBox tb = new TextBox();
form.add(tb);
tb.setText("text");
tb.setName("tb");
final DialogBox dlg = new DialogBox();
dlg.setWidget(form);
dlg.show();
delayTestFinish(TEST_DELAY);
form.addSubmitCompleteHandler(new SubmitCompleteHandler() {
@Override
public void onSubmitComplete(SubmitCompleteEvent event) {
// Make sure we get our results back.
assertTrue(event.getResults().equals("tb=text"));
finishTest();
// Hide the dialog on submit complete. This was causing problems at one
// point because hiding the dialog detached the form and iframe.
dlg.hide();
}
});
form.submit();
}
Aggregations