The dialog widget can be resized by the user, as well as programatically, using the API. Dialogs can also be dragged around on the screen if the draggable
option is left on — the default. Sometimes, just like a real desktop window, you may want to maximize the dialog to occupy the full browser window. Blot out all the other distractions, so to speak.
Thursday, July 3, 2014
jQuery UI: Maximizing Dialogs
Thursday, February 13, 2014
Retaining Scroll Position With Dialogs
If you set the height of a jQuery UI dialog widget, the content will scroll vertically. This is the expected result — the .ui-dialog-content
div
sets the overflow
CSS property to auto
. However, issues take place when you have multiple dialogs, and content that scrolls inside each. Because of the way focusing works, the vertical scroll bar moves back to the top, whenever the dialog loses focus. Ideally, the user would expect the scroll bar to retain it's position, no matter which dialog has the focus.
Friday, January 31, 2014
Adding Buttons To The Dialog Titlebar
The titlebar of the dialog widget contains, surprisingly, the dialog title. But it also contains the close button. This is a useful component of the dialog that's mostly closed off to the developer, at least as for as the widget API is concerned. The best you can do is set the title text, or respond to the close event when the close button is clicked. Depending on your dialog content, the title bar may be the appropriate place to add new dialog buttons. The buttons
option lets the developer add larger text buttons to the bottom of the dialog. But again, maybe that's not what you're after. You can extend the dialog widget and add a new option that allows developers to add new icon buttons to the titlebar.
Thursday, January 30, 2014
Displaying a Dialog Loading Message
Oftentimes, displaying a dialog widget requires loading remote data, used to populate the dialog content. This presents a usability issue — the user has to wait for the data to load, and so there should be some visual indication that the data is loading. One solution to this problem might be to open the dialog, and rather than displaying the actual dialog content (you don't have the actual content yet), display a simple loading message. Once the real content arrives, this temporary loading message is replaced. This approach works fine. The challenge, however, is that it's tough to make a loading message look good in a dialog. The other issue is the resizing of the dialog, once the content is formatted and inserted.
Wednesday, January 22, 2014
Advanced Dialog Effects
The jQuery UI dialog widget has a show, and a hide option — each of which are used to specify effect options for their respective actions. The show
option is applied any time the dialog is opened, while the hide
option is applied when the dialog is closed. They're one of those options that tries to be flexible, and at times this is misleading. For example, you're free to pass in a string, a boolean, a number, or an object with several effect properties. Everything other than the object type are intended to simplify the option. If you only want to enable the show/hide effect, you pass a boolean. If you want to specify the duration you pass a number while a string specifies the effect name to run.
Monday, January 13, 2014
Remove Dialog Close Button Focus
Wednesday, January 8, 2014
Default Widget Options
Monday, December 9, 2013
Responding To Dialog Open and Close Events
dialogopen
event is how this change is communicated to the outside world. This means that any element can listen to these events, including the body element. Listening for dialog events after they've bubbled up the DOM is handy for implementing generic behavior.Thursday, November 28, 2013
jQuery UI: Dialog Close Button Text
Wednesday, November 6, 2013
jQuery UI: Dialogs and URLs
autoOpen
option to false. Developers can choose the approach to take in how dialogs are created, and subsequently opened. For example, the default mode let's us work with short-lived dialog widgets. They're displayed when instantiated, destroyed when closed. This life-cycle works fine for the most part and is very resource-friendly. The alternative is to created your dialog widgets upfront, and simply call the open()
and close()
methods. What's common to both approaches is that they're reacting to some using event. It could be something has finished loading, or the more common case, the user has clicked something can in response, we want a dialog displayed. What about responding to URL changes?Friday, November 1, 2013
Position Dialog Based On Click Events
position
option. By default, the dialog opens automatically, and so if you need the default position changed, you have to specify the custom position when the widget is first instantiated.Tuesday, October 29, 2013
jQuery UI: Quick and Dirty Dailog Bar
Thursday, October 17, 2013
jQuery UI: Parameters in Dialog Callbacks
Wednesday, September 25, 2013
When To Use Dialog Widgets
Thursday, September 29, 2011
Disabling jQuery UI Dialogs
The dialog widget isn't a perfect fit for everyone — some might prefer the approach of displaying forms in-line on the page as opposed to having the form jump out at them. But aside from individual user preferences, there are a few implementation issues with displaying data in dialog widgets. Some major API redesign is lined up for the 1.9 version of the dialog widget, aimed at solving some of these imperfections.
One issue I'm interested in seeing worked out is proper disabling of the dialog widget. Subtle cases, where not having the dialog entirely disabled, cause some weird side-effects. And then there are not so subtle breakages where we need to fetch remote data.
Forms and remote data
Forms wouldn't be vary useful in the context of web applications if they didn't somehow interact with the server. For example, submitting a forms often means dispatching a POST HTTP request from the browser to the application server, resulting in a new resource. Sending data to the server is one avenue to interacting with remote data — but the user who submitted the form will need feedback — how else will they know if the action succeeded or not?
The response generated from the form submission should be presented to the user. More often than not, the user will have made an error in one or more fields, so the user interface will need to convey this. The error message — or error messages — typically go beside the errant field.
Dialog widgets that display forms to users have another potential use for remote application data and that is the form itself. Imagine a user clicks a registration button, located on the homepage, which then displays the form in a dialog widget. Now, imagine that this website has several other public informational pages that do not require a login, but nonetheless, we still to display the registration button on these pages. The registration form is the same on all pages.
So where does the dialog widget get the actual markup for this form? The jQuery UI dialog widget uses a div element as it's template — whatever is inside the div is displayed when the dialog is opened. This means that we'll have to insert the form markup on every page where the registration button is present. A solution to avoid duplicate registration forms is to make an Ajax call when the button is clicked. Instead of just opening the dialog, we'll populate the div with remote data first — this way we're only duplicating the URI pointing to the form on each page instead of the form itself.
Three methods in which the form displayed inside a jQuery UI dialog can communicate with the application server — through submitting data, through receiving responses, and through loading the initial form. On their own, the methods aren't difficult to comprehend and implement, but latency and usability are always a concern. An Ajax-based form can take on several states when presented inside a dialog, some of which require the form be disabled.
Disabling form elements
There comes a point, during the communication from the form to the application server, where it'll need to be disabled. Disabling means giving the user a visual cue that the element is temporarily paralyzed. Also, disabled widgets shouldn't respond to user events.
For example, let's say the user has just opened up a registration form inside a dialog widget. Before it can be displayed, we need to retrieve the actual form HTML and insert it into the dialog. In the mean time, while the HTTP request is happening in the background, there isn't anything for the user to see — there is nothing to display in the dialog yet. If we defer displaying the dialog until the form is ready, it appears to the user as though nothing has happened yet — sluggish responses are discouraging.
Display the dialog in a disabled state while the form loads.
What about when the user has actually submitted form data and is awaiting the result? We could hide the dialog entirely while the Ajax response churns. But this is clumsy as there is high probability of having to display the form again for the user to correct errors. It seems the logical solution is to keep the dialog visible, but disabled, just while processing happens. This is a friendly way, a responsive way, to indicate that stuff is happening.
Simple solution to a difficult problem
There are scenarios when using jQuery UI dialog widgets where it makes sense to disable it. Especially when dealing with forms as mentioned above. Sending and receiving remote data while the dialog is open means users can interact with it — unless it's properly disabled. However, while data is being transferred — from the browser to the server — or vice versa — there is a short latency duration.
Ajax-style applications cannot avoid latency during HTTP requests that take place in the background. Or, at least they cannot work under the assumption that the network response time will be faster than user actions. Preventing the user from performing certain actions is easy — it becomes difficult when we take into account the perceived responsiveness of the user interface. There is a delicate balance between ensuring correct behavior while remaining intuitive.
The solution to this problem, as we'll see in the 1.9 release of the jQuery UI dialog widget is to place a div element over top of the dialog, preventing the user from making changes during background processing. The best part about this enhancement, however, is that there is now a simple API for the dialog widget that'll make it disabled. This greatly simplifies many usage scenarios where we're waiting on the application server — we can simply disable the dialog and re-enable it instead of stringing together a boisterous solution.
Tuesday, August 25, 2009
jQuery UI Dialog Buttons
The button configuration for the jQuery UI dialog widget is specified as a javascript object containing all the buttons to be displayed in the dialog. Each attribute of the object maps to the text displayed inside each dialog button. The value of these attributes are the callbacks that are executed when the button is clicked.
However, there are a few problems to this approach. Firstly, the text of these buttons is difficult to update without replacing the entire button set. This is not only computationally expensive, but is also not an ideal way to couple code since the same operation has two responsibilities. Updating the dialog button text of a particular button and replacing all buttons entirely should be two distinct operations. Secondly, this also relates to the first problem, the dialog buttons cannot be uniquely identified easily.
A better configuration format might be to specify a DOM ID for each button in the main button configuration object. So the button would then have a unique handle. Underneath each DOM button ID would be another object specifying the button label and the button callback event.