tags:

views:

49

answers:

1

How can I cancel a form submission using GWT?

I need to validate the form and process some of the data before actually submitting it.

So far I did the following, the problem is that the form is submitted even if the SubmitEvent is cancelled.

form.addSubmitHandler( new SubmitHandler() {
        @Override
        public void onSubmit(SubmitEvent event) {
            if(validate()) {
                // i do some processing here
                form.submit();
            }

            else event.cancel(); // submits anyway
        }
    });

Is this a GWT issue? How should I do?

edit: I just found out that if it was a Button that uses form.submit() on click, the submit event is cancelled. However if a SubmitButton is clicked, the event is not cancelled.

So I guess this is a browser behavior. Still, I need to find way...

edit: just found out that it does only happen in development mode, I feel silly not to have tried outside development mode before.

A: 

It's an issue that only happen in development mode

I have reported the issue: http://code.google.com/p/google-web-toolkit/issues/detail?id=5067

Florian d'Erfurth
I think you forgot to add that it only happens when a SubmitButton is used (?).
Igor Klimer
Ooops indeed, thanks :)
Florian d'Erfurth