Search in sources :

Example 1 with SubmitHandler

use of org.gwtproject.user.client.ui.FormPanel.SubmitHandler 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 2 with SubmitHandler

use of org.gwtproject.user.client.ui.FormPanel.SubmitHandler in project gwtproject by treblereel.

the class FormPanelTest method testNamedTargetSubmitEvent.

public void testNamedTargetSubmitEvent() {
    // Create a form and frame in the document we can wrap.
    String iframeId = Document.get().createUniqueId();
    String iframeName = Document.get().createUniqueId();
    final Element container = Document.get().createDivElement();
    container.setInnerHTML("<form method='post' target='" + iframeName + "' action='" + "formHandler?sendHappyHtml'>" + "<input type='submit' id='submitBtn'></input></form>" + "<iframe src=\"javascript:\'\'\" id='" + iframeId + "' " + "name='" + iframeName + "'></iframe>");
    Document.get().getBody().appendChild(container);
    // Wrap the form and make sure its target frame is intact.
    FormPanel form = FormPanel.wrap(container.getFirstChildElement());
    assertEquals(iframeName, form.getTarget());
    // Ensure that no synthesized iframe was created.
    assertNull(form.getSynthesizedIFrame());
    // Submit the form using the submit button and make sure the submit event fires.
    delayTestFinish(TEST_DELAY);
    form.addSubmitHandler(new SubmitHandler() {

        @Override
        public void onSubmit(SubmitEvent event) {
            finishTest();
        }
    });
    Document.get().getElementById("submitBtn").<InputElement>cast().click();
}
Also used : HTMLIFrameElement(elemental2.dom.HTMLIFrameElement) InputElement(org.gwtproject.dom.client.InputElement) Element(org.gwtproject.dom.client.Element) SubmitHandler(org.gwtproject.user.client.ui.FormPanel.SubmitHandler) SubmitEvent(org.gwtproject.user.client.ui.FormPanel.SubmitEvent)

Aggregations

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