Creating a HTML Editor for your Text Areas


One of the updates from version 3.0 to 3.1 is that Text Areas now use HTML rather than RTF (Rich Text Format).  However, there is no way to enter raw HTML directly in the Text Area.  By using a combination of a Property Control (to enter the HTML) and a Script Control (to display the HTML using the API), we can create an HTML editor which will allow you to enter HTML code and then create a new Text Area to display it in.  

First, we need to create the Property Control. For this we will use a multi-select list box and size it to be wider and higher than the default.



This will be the control that the users can enter HTML into.  

Second, we need to create a Script Control which will create a new Text Area and then display the HTML in the Text Area.

from Spotfire.Dxp.Application.Visuals import HtmlTextArea
textArea = Document.ActivePageReference.Visuals.AddNew[HtmlTextArea]()
textArea.AutoConfigure()
textArea.HtmlContent = strHTMLContent

The value from the property created earlier is passed in as an input parameter (called strHTMLContent) to the Script Control.

When you are done, you can test it out (as shown below).  



Although this feature will also work in the Web Player, the real use case it to allow an author to have more control over the layout and style of the text area, including tables, style sheets, remote images, and even some nifty things like audio and video.