WYSIWYG Editor in Salesforce Scontrols

Until Salesforce adds a native option for WYSIWYG editing controls for text areas (promote the idea) the only workaround is to create an Scontrol form that calls on other Javascript toolkits to handle this functionality.

Salesforce hosts the Dojo Toolkit but unfortunately there is a lack of definitive documentation on employing it in Scontrols. I wanted to create an scontrol that uses the Dojo Editior (http://dojotoolkit.org/book/dojo-book-0-9/part-2-dijit/advanced-editing-and-display/editor-rich-text) to give the user WYSIWYG controls for a text area.

Thanks to some assistance from fellows on the forums at developer.force.com I was able to put together a working prototype. Here is the working code;

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
"http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8">
<title>Editor Demo</title>
<style type="text/css">
@import "/js/dojo/0.9/dijit/themes/tundra/tundra.css";
@import "/js/dojo/0.9/dojo/resources/dojo.css"
</style>
<script src="/soap/ajax/10.0/connection.js"></script>
<script type="text/javascript"
src="/js/dojo/0.9/dojo/dojo.js"
djConfig="parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dijit.Editor");
</script>

</head>
<body class="tundra">
<form method="post">
<textarea name="field" width="200px"
dojoType="dijit.Editor">
It was a dark and stormy night. Your story belongs here!
</textarea>
<input type="submit" value="Save" />
</form>
</body>
</html>

There still remains the javascript needed to load the data from a text area field into the editor on page load and the function for saving the edited text back to that field. Since that varies greatly depending on the object you are using, I leave that to you.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s