Skip to content

Categories:

IE form submit issue with return key

Don’t you love Internet Explorer? Man if this browser didn’t exist just thing of the millions of dollars/euro/etc that would be saved every week from developers not having to graple with Microsofts buggy/hard-to-work-with browser. I will be a happy man the day it dies.

Anyhow the reason for the post: We noticed here that IE handles return key pressed events different when submitting a form. We have a form with a signal TextArea and a AjaxButton. In Firefox when either clicking on the button or hitting return in the text area we would arrive on our AjaxButtons onSubmit method. All good and dandy.
However
In IE when clicking on the button everything worked as expected. But when hitting return we found that the page just refreshed and the onSubmit of the ajaxbutton was not called. It turns out that FF and IE handle this differently. FF will look for the first button in the form and submit that, where as IE simply submits the whole form.
This means we had to implement the onSubmit in the form as well as the AjaxButton onSubmit.

Problem here is you end of duplicating code as you only have the AjaxRequestTarget on the ajaxbutton onSubmit. Jeremy Thomerson came up with a couple fo suggestions one of which we have implemented do get rid of this duplicate code. I’d be interested to know if anyone has come up with a better way of handling this:


= new Form() {

   add(new AjaxButton() {
      void onSubmit() {
           if(!form.isSubmitted()) {
                 onSubmit();
           }
      }

  void onSubmit() {

      IRequestTarget iTarget = RequestCycle.get().getRequestTarget();
      AjaxRequestTarget target= null;
      if (iTarget instanceof AjaxRequestTarget) {
          target = (AjaxRequestTarget) iTarget;
      }

      //logic..

   }
}

This seems to work fine.

Share and Enjoy:
  • Digg
  • Print this article!
  • del.icio.us
  • Facebook
  • Google
  • E-mail this story to a friend!
  • Slashdot

Posted in general.

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.