YUI Library Home

YUI Library Examples: Rich Text Editor: Editor in a Dialog Control

Rich Text Editor: Editor in a Dialog Control

In YUI-based applications, it's common for forms to appear as part of Dialogs. In this example, a form enhanced with the Rich Text Editor appears in a Dialog. Read the tutorial below to learn how to integrate the RTE seamlessly with your Dialog's form contents.

Enter Title and Description:

Dialog's post response will appear here after you submit the Dialog.

Using Rich Text Editor in a Dialog Control

When using a Rich Text Editor in a Dialog Control, there are a few considerations:

  • The editor and the elements it creates (particularly the floating properties palettes) need to be rendered into the Dialog's DOM structure. If the Dialog is modal, it will try to maintain focus within its DOM confines, so ensuring that all editor elements are children of the Dialog's DOM is crucial.
  • The most common way to submit a Dialog's form contents is asynchronously using Connection Manager. This means that editor cannot automatically attach itself to the form's submit event. Instead, we need to call the editor's saveHTML method prior to executing the Dialog's submit method.
  • The Rich Text Editor needs special handling when it is hidden (ie, when a parent element is set to display:none). Dialogs, of course, are usually hidden by default and appear only in response to user action. As a result, we need to listen for the Dialog's showEvent and hideEvent and prepare the Rich Text Editor to recover gracefully when the Dialog is hidden from view.

These three considerations are each accounted for in the code below, which is fully commented and represents the full JavaScript source for this implementation:

Configuration for This Example

You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.

Copyright © 2011 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings