Related Categories: Web Dev

ColdFusion 8 has a handy new tag to instantly create a rich text editor in your forms.  It uses FCK editor.

Anyone who has spent a few minutes with it has noticed that the two toolbar configs that it comes may not fit your needs.  In fact the Basic toolbar has a Link option in it.  This link option creates a popup window that presents a button to browse the server and on another tab a form to upload documents.  Don't panic, the functionality to actually browse or upload has been rmoved (file not found error).  Why did they leave in the buttons and form?  Who knows.  This is not acceptable to present to any end user or client, however.

So, the logical thing to do is:

  1. Replace the file in the cfide/ path with the original file so it works.  You don't want to do this for editors exposed to the general public of course, as you don't want them uploading documents and browsing your server.
  2. Remove the offending code from the cfide source.
  3. Specify new toolbar configs in the fckconfig.js file.

All three options assume that you have access to the server.  No big deal if you have your own server, not an option if you are on a shared host or if you write software that will be installed on lots of different servers.

4. A fourth option and really the only other option given thus far for those without access to the cfide code  is to specify your own fckeditor path in the cftextarea and then upload the entire fckfolder.  This means for each install you may have to have a whole copy of all the fckeditor code.  This is kind of lame for many reasons.

I have worked for a bit to come up with a fifth option.  It wont fix the file browse issue, Adobe will likely address that shortly.  It will give us more flexibility in how to implement the toolbar options.

5. Change the toolbar setup on runtime with javascript.

This code:

  • Creates a function called 'FCKeditor_OnComplete()'  that FCKeditor runs when the editor is completely rendered.  FCK checks if this function exists, and runs if so.
  • Then we specify our new toolbar congig.
  • Then we load that new toolbar config.
function FCKeditor_OnComplete(editorInstance)
{
 editorInstance.Config["ToolbarSets"]["BasicMin"] = [
 ['Bold','Italic','Underline'],
 ['OrderedList','UnorderedList'],
 ['TextColor','BGColor']
 ];

editorInstance.EditorWindow.parent.FCK.ToolbarSet.Load('BasicMin' ) ;
}

This way we don't need to modify any original source files, don't need to upload any other files, etc.

The one drawback to this is there will be a moment when the default toolbar or basic toolbar is shown before the new toolbarset is applied.  That short flicker is something I can't seem to get around.  But hey, its better than options 1-4 for many of us.

On a side note, I thought that the .config toption would do this without my having to use .load.  But no, it simply does nothing unless I follow it up with .load.  I haven't found a cleaner way, though one may certainly exist.  If anyone has any other options, be sure to comment and share with the rest!


Like this entry? Subscribe to my blog.

Comments (moderation on)

I haven't checked out the functionality of the cftextarea much but I am pretty disappointed that the file upload wasn't implemented. When setting up FCK by yourself that is the only part that is even minutely complicated to get working and the only part that actually requires an application server like CF...so why leave it off?

As for the other issue, I would assume they will have that fixed in an updater.
# Posted By Brian Rinaldi | 11/28/07 2:58 PM
If you really want to remove the ability to edit links, then that solution would be fine, but to address just the original issue, changing the configuration on the fly (using your approach) looks a better option to me:

function FCKeditor_OnComplete(editorInstance)
{
   editorInstance.Config.LinkBrowser = false ;
   editorInstance.Config.LinkUpload = false ;
}
# Posted By AlfonsoML | 11/28/07 4:01 PM
Actually what I was going for was to have complete control over what ubttons show up in the editor. It was caused because I didn't want the link button there, but once I got going I realized I wanted many other buttons to be present. Basically default and basic configs where not right, and I didn't want to include the entire script source for the install.
# Posted By Joshua Cyr | 11/28/07 5:00 PM
Cool tip. Just used it.
# Posted By Sam Farmer | 7/8/08 4:46 PM
If I remember right I had to give up on it as there were browser incompatibilities. That was before the 8.0.1 update though. It may be just fine with the updater.
# Posted By joshua | 7/8/08 4:48 PM

Sponsors


Savvy Content Manager