views:

4344

answers:

2

I have a JQuery UI dialog popup that displays a form. By selecting certain options on the form new options will appear in the form causing it to grow taller. This can lead to a scenario where the main page has a scrollbar and the JQuery UI dialog has a scrollbar. This two scrollbar scenario is unsightly and confusing for the user.

How can I make the JQuery UI dialog grow (and possibly shrink) to always fit its contents without showing a scrollbar? I would prefer that only a scrollbar on the main page is visible.

+3  A: 

The answer is to set the

autoResize:true

property when creating the dialog. In order for this to work you cannot set any height for the dialog. So if you set a fixed height in pixels for the dialog in its creator method or via any style the autoResize property will not work.

MikeN
Fantastic :) but why jQuery didn't put that at their documentation ?!. Anyway thank u .
Wahid Bitar
+3  A: 

Use the autoResize:true option. I'll illustrate:

  <div id="whatup">
    <div id="inside">Hi there.</div>
  </div>
   <script>
     $('#whatup').dialog(
      "resize", "auto"
     );
     $('#whatup').dialog();
     setTimeout(function() {
        $('#inside').append("Hello!<br>");
        setTimeout(arguments.callee, 1000);
      }, 1000);
   </script>

Here's a working example: http://jsbin.com/ubowa

altCognito
Hmm.. will have to extend my [FrameDialog](http://plugins.jquery.com/project/jquery-framedialog) ... it's essentially a method that creates an iframed content for use with dialog.. it isn't perfect, but working well for a project I needed it for.
Tracker1
This didn't work for me. Instead, I set the option "width" to "auto".
Sam
+1 to the comment -- it worked for me, and the example works as well, so I have to imagine this hasn't changed, but hey, if all else fails, give it a shot.
altCognito
This doesn't work for width though, it only works for height I think.
Walt W
This answer is no longer valid for version 1.8.4 instead use height auto http://forum.jquery.com/topic/dialog-auto-width
Jeff