Forum OpenACS Q&A: Passing value to richtext editor

Request notifications

Collapse
Posted by Paul Babin on
Hello -

I've been successfully calling ckeditor4 in a number of our applications in 5.9.1 for create pages: however, I'm running into a issue for ae pages and am curious if anyone else has run into this issue.

The issue is that when I add ckeditor in the tcl code for an ae page - the value is not passed to the editor. I've seen something like this when I was adding ckeditor on the adp page and fixed it by making sure the value was passed after ckeditor was initiated. I'm not sure how to address this in the tcl code and hope it is just a minor fix.

This is the code that I am currently using

    {publish_body:richtext(richtext),optional
        {value "$publish_body"}
        {options {
            editor ckeditor4
            plugins {autogrow,codemirror,widget,lineutils,colordialog,dialog,fakeobjects,filebrowser,popup,iframedialog,balloonpanel,"..more plugins"}
            customConfig {/resources/ckeditor/config.js}
            skin {office2013,/resources/ckeditor/skins/office2013/}
        }
        }
    }
Any suggestions are greatly appreciated.

Collapse
Posted by Gustaf Neumann on
since nobody is replying, i am trying to help, although i know nobody who is using "ae". The whole initialization happens for the ckeditor via initialize_widget [1], which adds finally the init code via "template::add_script" and "template::head::add_javascript". These settings are picked up later in the "blank-master".

Since "ae" stands probably for "Anonymous Evaluation", it might be the case that there are different templates are used (maybe omitting the blank-master). Do you see the JavaScript code in the page, where the editor is supposed to appear?

all the best
-gn

[1] https://openacs.org/api-doc/proc-view?proc=richtext::ckeditor4::initialize_widget&source_p=1

Collapse
Posted by Paul Babin on
My apologies, it looks like ae is something we use internally here. Add-Edit. These are pages that are used both to add content to the database in a news package or an events package and to edit the content using the same form.

ckeditor is successfully added to both instances (add and edit) - so the initialization widget is doing what it is supposed to do as far as rendering the editor: however, the data inputed into publish_body during the add does not appear when you edit.

Collapse
Posted by Antonio Pisano on
Not sure if this can be of help, but how is richtext value saved internally? Richtext widgets treat their values as a list in the form {content mime_type} and might misbehave if they are fed with content only.
Collapse
Posted by Gustaf Neumann on
Another suspicion: can it be, that the page contains multiple fields with the identical names?
Collapse
Posted by Paul Babin on
Antonio - thank you - I believe this may lead me to address the issue. And please excuse what may be novice questions as I mostly deal with frontend applications.

I followed the entry down to the table public.cr_revisions and the column for my text field is labeled content and its type is text. To me this seems correct; however, if you go three lines up there is mime_type with type "character varying(200) and modifiers "default 'text/plain/::character varying. Is this why its not behaving correctly?

Collapse
Posted by Paul Babin on
Gustaf,

As always thank you for your time in responding.

The page only has one field with that name. We've done some additional testing and still cannot determine what the issue is.

The best that I can describe as is that the richtext widget doesn't know what to do with the stored value of $publish_body. We hardcoded a value on request as "Test $publish_body" with publish_body:text(richtext) in the ad_form - Test shows in the widget area but not $publish_body.

At this time my workaround is to change publish_body:text(richtext) to publish_body:text(text) and then call ckeditor as an external editor via manually added javascript.

As we transition a number of our sites over to 5.9.1 I'll see if any of our revision pages in other packages that pull content from the database have the same issue. If the richtext editor displayed inputted content then I'll know the culprit is in the coding of that package and if not, I'll do some more digging in and report back.

Collapse
Posted by Antonio Pisano on
This looks as I thought: try in your test to hardcode the value as [list "Test $publish_body" "text/html"]. It should work as expected

Ciao

Collapse
Posted by Paul Babin on
Antonio! This worked beautifully like magic! I cannot express my gratitude enough for the assistance on this!

For anyone that comes across this entry - before we got this working, I tried my previous work around of adding the editor directly to the page. If you are using 5.9.1 with csp turned on, adding ckeditor externally will not work so do not waste your time to try to add it. Even with adding security::csp::require for all csp items, ckeditor will not render properly. Its best recommended to call the editor within your tcl code.