.. _dijit/Dialog: dijit.Dialog ============ :Available: since V? :jsDoc: http://api.dojotoolkit.org/jsdoc/HEAD/dijit.Dialog .. contents:: :depth: 2 ============ Introduction ============ Dijit's modal Dialog Box simulates a regular GUI dialog box. The contents can be arbitrary HTML, but are most often a form or a short paragraph. The user can close the dialog box without acting by clicking on the X button in the top-right corner. ===== Usage ===== .. code-block :: javascript :linenos: After creating a Dialog, the Dialog (and the underlay) moves itself right behind the
element within the DOM, so it can overlay the entire webpage. With this move no other elements parent the Dialog.domNode. Therefore you have to add a ``class="tundra"`` attribute (or some other applicable :ref:`theme nameWhen pressing this button the dialog will popup:
.. cv:: javascript :label: The javascript, put this wherever you want the dialog creation to happen Note that dialog's source markup can be hidden via specifying style="display: none", to prevent it from flashing on the screen during page load. However, hiding the dialog indirectly via a class won't work (in that the dialog will remain invisible even when it's supposed to be displayed). Dialog programmatically ----------------------- Now lets create a dialog programmatically, and change the dialog's content dynamically .. cv-compound:: A programmatically created dialog with no content. First lets write up some simple HTML code because you need to define the place where your Dialog should be created. .. cv:: htmlWhen pressing this button the dialog will popup. Notice this time there is no DOM node with content for the dialog:
.. cv:: javascript :label: The javascript, put this wherever you want the dialog creation to happen Coloring the Underlay --------------------- If you wish to alter the default color for the underlay, you do so in CSS. The underlay receives an ID to match the Dialog, suffixed with :ref:``underlay``, which you can define a css class for: .. cv-compound:: .. cv:: htmlWhen pressing this button the dialog will popup:
.. cv:: javascript Forms and Functionality in Dialogs ---------------------------------- This example shows a Dialog containing form data. You can get the form data as a javascript object by calling attr('value') on the dialog. To prevent the user from dismissing the dialog if there are errors in the form, add an onClick handler to your submit button. In order to run Dialog's execute-method the submit button has to be a dijit.form.Button, normal submit button doesn't trigger this function. In addition, the form has to be local, the dialog doesn't find the form values if it's included via href attribute. To simply close the dialog, click the Cancel button, which calls the hide() function on the Dialog. .. cv-compound:: .. cv:: htmlWhen pressing this button the dialog will popup:
.. cv:: javascript :label: The javascript, put this wherever you want the dialog creation to happen External Dialog content using HREF attribute -------------------------------------------- You can also load dialog content from another page by setting HREF attribute for the widget. Note that the Dialog doesn't execute script tags inline external content. However, it parses the page for widgets, so you can add functionality to widgets by connecting into widget extension points using declarative markup (DojoML; e.g. `` .. cv:: htmlWhen pressing this button the dialog will popup loading the dialog content using an XHR call.
Sizing the Dialog ----------------- A dialog by default sizes itself according to it's content, just like a plainLorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean semper sagittis velit. Cras in mi. Duis porta mauris ut ligula. Proin porta rutrum lacus. Etiam consequat scelerisque quam. Nulla facilisi. Maecenas luctus venenatis nulla. In sit amet dui non mi semper iaculis. Sed molestie tortor at ipsum. Morbi dictum rutrum magna. Sed vitae risus.
When pressing this button the dialog will popup (with a scrollbar):
============= Accessibility ============= Keyboard -------- ==================================================== ================================================= Action Key ==================================================== ================================================= Navigate to next focusable element in the dialog tab Navigate to previous focusable element in the dialog shift-tab Close the dialog escape ==================================================== ================================================= Keyboard Navigation in Release 1.1 and later ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ When a dialog is opened focus goes to the first focusable element within the dialog. The first focusable element may be an element which appears in the tab order by default such as a form field or link, an element with a tabindex attribute value of 0 or an element with a tabindex value greater than 0. Elements with a tabindex value greater than 0 will appear in the tab order before elements with a tabindex of 0 or those in the tab order by default. If the dialog does not contain a focusable item, focus will be set to the dialog container element when the dialog is opened. The same focus behavior has been implemented for tooltip dialog When focus is in a dialog, pressing the tab key will move focus forward to each focusable element within the dialog. When focus reaches the last focusable element in the dialog, pressing tab will cycle focus back to the first focusable item. Pressing shift-tab will move focus backwards through focusable elements within the dialog. When the first focusable item is reached, pressing shift-tab will move focus to the last focusable item in the dialog. Keyboard Navigation Previous to Release 1.1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ When a dialog is opened focus goes to the title section of the dialog. This was implemented to provide screen reader support to speak the title of the dialog when it is opened. Likewise, when a tooltip dialog is opened, focus is placed on the container of the tooltip dialog. In future versions of the dialog and tooltip dialog widgets, focus will go to the first item in the dialog or tooltip dialog. When focus is in a dialog, pressing the tab key will move focus forward to each focusable element within the dialog. When focus reaches the last focusable element in the dialog, pressing tab will cycle focus back to the dialog title. Pressing shift-tab will move focus backwards through focusable elements within the dialog until the dialog title is reached. If focus has previous cycled forward through all of the elements, pressing shift-tab with focus on the dialog title will move focus to the last element in the dialog. If focus has not previously been cycled through all of the focusable elements in the dialog using the tab key, pressing shift-tab with focus on the dialog title will leave focus in the title. The same focus cycling applies to the tooltip dialog as well with focus being set to the tooltip dialog container since there is no dialog title. Improved Screen Reader Support in 1.4 ------------------------------------- The dialog now supports the aria-describedby property. If you have a description of the dialog that you would like spoken by the screen reader when the dialog opens add the aria-describedby property to the dialog. Include an element containing the text you want spoken in the dialog. The value of the aria-describedby property is the id of the element containing the text. .. code-block :: javascript