The Dialog component is an extension of Panel that is meant to emulate the behavior of an dialog window using a floating, draggable HTML element. Dialog provides an interface for easily gathering information from the user without leaving the underlying page context. The information is collected via a standard HTML form; Dialog supports the submission of form data either through an XMLHttpRequest, through a normal form submission, or through a fully script-based response (where the script reads and responds to the form values and the form is never actually submitted via HTTP to a server).
To use Dialog, include the following code in your page:
Instead of copying and pasting the filepaths above, try letting the YUI dependency Configurator determine the optimal file list for your desired components; the Configurator uses YUI Loader write out the full HTML for including the precise files you need for your implementation.
Note: If you wish to include this component via the YUI Loader, its module name is container. (Click here for the full list of module names for YUI Loader.)
Where these files come from: The files included using the text above will be served from Yahoo! servers; see "Serving YUI Files from Yahoo!" for important information about this service. JavaScript files are minified, meaning that comments and white space have been removed to make them more efficient to download. To use the full, commented versions or the -debug versions of YUI JavaScript files, please download the library distribution and host the files on your own server.
Order matters: As is the case generally with JavaScript and CSS, order matters; these files should be included in the order specified above. If you include files in the wrong order, errors may result.
Using "CSS skins": One of the files listed above contains a CSS "skin" for the Dialog Control. For this skin CSS to work correctly, you will need to apply the CSS class "yui-skin-sam" to an element that is a parent of the element in which the component lives. You can usually accomplish this simply by putting the class on the <body> tag:
<body class="yui-skin-sam">
For more information on skinning YUI components and making use of default skins, see our Understanding YUI Skins article here on the website.
This section describes common tasks for creating and using Dialog. It contains these sections:
Dialog inherits its constructor and configuration, as well as several other important methods, from Panel, and thus from Overlay. See Panel and Overlay for more information on how to utilize Dialog's inherited features.
HTML markup for Dialog uses the same modular format underlying Module. Because the core interaction supported by Dialog involves gathering information from the user via an HTML form, typically you place a form element in the "body" section of your Dialog module. Placing the form element in the page, rather than creating the form via script once the Dialog instance is created, enables you to use Progressive Enhancement — showing the full content and functionality to users who may have older browsers or who have JavaScript disabled while still providing a richer interaction to modern, standards-compatible browsers.
The following example illustrates the markup for a Dialog module:
The "action" attribute specified in the form is the one that is used to submit
the data, regardless of whether you have configured your Dialog (via the postmethod attribute)
to use XMLHttpRequest or standard form submission.
If no form is specified in your markup, one is automatically created for you by Dialog (its name attribute will be "frm_dialogid", where dialogid is the HTML element id you passed to the Dialog constructor). If you allow Dialog to create the form for you dynamically, be sure to set the form's action attribute by script if you wish the form to post via XMLHttpRequest or standard form submisison.
Dialog provides a configuration property called "buttons" that allows you to automatically wire up buttons with callbacks to display in the footer of the Dialog. Buttons are configured by creating an array of objects as illustrated in the following code sample. Note that you can configure a separate handler script to respond to each of the buttons.
Each button object in the buttons array can have three properties:
In the example above, the "buttons" property is queued up to be executed upon render of the Dialog.
NOTE: If you've included the optional YUI Button script on the page, the buttons created will be instances of YAHOO.widget.Button otherwise regular HTML Buttons will be created.
To instantiate a Dialog, use this code:
This constructor uses an element with an HTML ID of "myDialog" on the page; the markup example above provides a template for this markup. Once instantiated, you may wish to configure the form's buttons (see above) and then render your Dialog instance on the page:
Generally, Dialogs are hidden when the page loads and only appear when needed. To reveal your Dialog on screen, invoke its show method:
Submitting the Dialog via script is as simple as calling the submit function on the Dialog object:
The default postmethod for the Dialog is async. Upon submission of a Dialog whose postmethod configuration is set to async (meaning that it will use Connection Manager to post the form's data via XMLHttpRequest to the URI specified in the form element's action attribute), all of the appropriate Connection Manager callbacks documented in the API will be executed, allowing for easy handling of the response.
By default the Dialog is automatically hidden after submission, however the hideaftersubmit configuration property can be used to control this behavior.
For example, to set up the handlers for both successful and failing Dialog submissions when using an asynchronous form post, the code might look like this:
If the Dialog's form contains a file upload input control (<input type="file">) the Dialog will use Connection Manager's file upload support when sending
out the async request. For file uploads Connection Manager expects the callback to be defined with a single upload handler, replacing the success and failure handlers.
The upload handler will be invoked on completion of the transaction:
It's also valuable to note that the callback object referenced in the above example is passed directly to the Connection Manager, and therefore can accept the argument and scope properties in addition to success and failure. More information on the usage of these properties is available in the Connection Manager documentation.
Dialog provides a function called getData that returns a simple object structure with the form's current data. For instance, in the example above, if you wanted to find out what someone typed in the field called "firstname" you could retrieve that value from getData like such:
Dialog has the following configuration properties:
| Name | Type | Default | Description |
|---|---|---|---|
| postmethod | String | "async" | The method in which the Dialog's form should be posted. Options are "async", "form", or "none". |
| buttons | Object[] | null | Array of button objects to render at the bottom of the Dialog. |
Dialog has the following inherited configuration properties:
| Name | Type | Default | Description |
|---|---|---|---|
| visible | Boolean | true | Sets whether or not the Dialog is visible on the page (Dialog uses the CSS "visibility" property to control this). |
| effect | Object / Object[] | none | Sets the ContainerEffect (one or many) that should be used when showing and hiding the Dialog. |
| monitorresize | Boolean | true | Configures whether or not to create a hidden off-screen element that can be used to monitor for text size changes in the DOM. |
| x | Number | null | Sets the element's "left" style property. |
| y | Number | null | Sets the element's "top" style property. |
| xy | Array | null | Sets the element's "top" and "left" style properties. |
| context | Array | null | Allows the Overlay to be anchored to a context element. The format is: [element, elementCorner, contextCorner], where "element" is an element or element id, and the corner parameters are either "tr" (top right), "tl" (top left), "br" (bottom right), or "bl" (bottom left). |
| fixedcenter | Boolean | false | Specifies whether the Overlay should be automatically centered in the viewport on window scroll and resize. |
| width | String | null | Sets the element's "width" style property. |
| height | String | null | Sets the element's "height" style property. |
| zIndex | Number | null | Sets the element's "z-index" style property. |
| constraintoviewport | Boolean | false | If set to true the Overlay will try to remain inside the confines of the size of viewport. |
| iframe | Boolean | false (true by default for IE 6 and below) | If set to true the Menu will have and iframe behind it to prevent other elements with a higher z-index from poking through. |
| close | Boolean | null | Whether a "close" icon should be displayed in the header. |
| draggable | Boolean | "true" if the Drag and Drop utility is included, otherwise "false." | Whether to allow the user to drag the Panel using its header. |
| underlay | String | "shadow" | Specifies the type of underlay to display under the Panel. Other options include "none", and "matte", which renders a small white matte under the Panel. |
| modal | Boolean | false | Specifies whether the document should be shielded with a partially transparent mask to require the user to close the Panel before being able to activate any elements in the document. |
| keylisteners | YAHOO.util.KeyListener / Array | null | A KeyListener or Array of KeyListeners containing key events to enable when the Panel is displayed. |
| hideaftersubmit | Boolean | true | If set to true, the Dialog is hidden after it's submitted. If false, it is left visible after form submission. |
The YUI Library and related topics are discussed on the on the ydn-javascript mailing list.
In addition, please visit the YUIBlog for updates and articles about the YUI Library written by the library's developers.
The YUI Library's public bug tracking and feature request repositories are located on the YUI SourceForge project site. Before filing new feature requests or bug reports, please review our reporting guidelines.














Copyright © 2008 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings