Search in sources :

Example 1 with SubmitCompleteEvent

use of org.gwtproject.user.client.ui.FormPanel.SubmitCompleteEvent 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();
}
Also used : SubmitCompleteEvent(org.gwtproject.user.client.ui.FormPanel.SubmitCompleteEvent) SubmitCompleteHandler(org.gwtproject.user.client.ui.FormPanel.SubmitCompleteHandler)

Example 2 with SubmitCompleteEvent

use of org.gwtproject.user.client.ui.FormPanel.SubmitCompleteEvent 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();
}
Also used : HTMLIFrameElement(elemental2.dom.HTMLIFrameElement) InputElement(org.gwtproject.dom.client.InputElement) Element(org.gwtproject.dom.client.Element) SubmitCompleteEvent(org.gwtproject.user.client.ui.FormPanel.SubmitCompleteEvent) SubmitCompleteHandler(org.gwtproject.user.client.ui.FormPanel.SubmitCompleteHandler)

Example 3 with SubmitCompleteEvent

use of org.gwtproject.user.client.ui.FormPanel.SubmitCompleteEvent 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();
}
Also used : SubmitHandler(org.gwtproject.user.client.ui.FormPanel.SubmitHandler) SubmitCompleteEvent(org.gwtproject.user.client.ui.FormPanel.SubmitCompleteEvent) SubmitCompleteHandler(org.gwtproject.user.client.ui.FormPanel.SubmitCompleteHandler) SubmitEvent(org.gwtproject.user.client.ui.FormPanel.SubmitEvent)

Example 4 with SubmitCompleteEvent

use of org.gwtproject.user.client.ui.FormPanel.SubmitCompleteEvent 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&amp;ptb=password&amp;cb1=on&amp;rb0=on&amp;lb=value1&amp;h=v"));
            finishTest();
        }
    });
    form.submit();
}
Also used : SubmitCompleteEvent(org.gwtproject.user.client.ui.FormPanel.SubmitCompleteEvent) SubmitCompleteHandler(org.gwtproject.user.client.ui.FormPanel.SubmitCompleteHandler)

Example 5 with SubmitCompleteEvent

use of org.gwtproject.user.client.ui.FormPanel.SubmitCompleteEvent 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();
}
Also used : SubmitCompleteEvent(org.gwtproject.user.client.ui.FormPanel.SubmitCompleteEvent) SubmitCompleteHandler(org.gwtproject.user.client.ui.FormPanel.SubmitCompleteHandler)

Aggregations

SubmitCompleteEvent (org.gwtproject.user.client.ui.FormPanel.SubmitCompleteEvent)5 SubmitCompleteHandler (org.gwtproject.user.client.ui.FormPanel.SubmitCompleteHandler)5 HTMLIFrameElement (elemental2.dom.HTMLIFrameElement)1 Element (org.gwtproject.dom.client.Element)1 InputElement (org.gwtproject.dom.client.InputElement)1 SubmitEvent (org.gwtproject.user.client.ui.FormPanel.SubmitEvent)1 SubmitHandler (org.gwtproject.user.client.ui.FormPanel.SubmitHandler)1