Tuesday, June 14, 2011

jQuery UI dialog - form not post

Symptoms
I applied the jquery-ui dialog, but now when I click on it, the submit input ( or button ) doesn't do a normal form post.

Case Study
For example, for whatever reasons, you have html like this (just for demo purpose only)

<form name="stuff" action="whatever/listener" method="post">
   <div class="myDialog">
         <input type="submit" value="Submit" />
   </div>
</form>

You applied the jquery dialog on that element as the following,

$('.myDialog').dialog({
            height: 'auto',
            modal: true,
            resizable: false,
            draggable: false,
            autoOpen: true,
            width: 'auto'
});

Everything works fine from UI perspective... Oops, but all of a sudden, you find that the form dialog submit button is not posting to the form... What happen??

Reason
Well, first of all, before trying any methods, try to disable that dialog, and see if the form posts without it. If the form posts without the dialog, then you know you can localize the problem.

If you confirm that it is a jquery dialog issues, then I can tell you that the jquery dialog could move your DOM out of its original place, and that's the reason why the form post doesn't work.

Solution
You can move the dialog box content back to the form by doing this
$(".myDialog").parent().appendTo("/html/body/form[0]");

5 comments:

  1. this is so interesting, THANKS for the post roy! (do not delete)

    ReplyDelete
  2. Wow...as a backend engineer..."glad" to know how a FE jQuery change could cause this...

    Ming

    ReplyDelete
  3. nice article sir...got some idea about history of project management..thanks a lot for your post ..you could have added information about.You can test your knowledge in html by attending HTML Quiz .

    ReplyDelete
  4. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.
    html5 audio player

    ReplyDelete
  5. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.
    html5 audio player

    ReplyDelete