We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22980
    • 84 Posts
    Hi again

    On my document page, I have a custom tinyMCE textarea which gets submitted through ajax. (it is, in fact, created with modx’s own functions.) However, it is behaving very strangely:

    As expected, tinyMCE.triggerSave(); is required to give the textarea its html. So this works:
    tinyMCE.activeEditor.setContent(’pancake?!’);
    tinyMCE.triggerSave();
    alert(tinyMCE.activeEditor.getContent());

    And getting the textarea value provides ’pancake?!’

    However, this all happens totally disconnected from the actual ’physical’ tinyMCE editor - any text typed in the editor will not be grabbed by triggerSave or getContent, and ’pancake?!’ is does not replace the editor’s text.

    Now, the only idea I have is that somehow the activeEditor is not the one I’m seeing on the page, but somehow referring to another editor somewhere. To support this, the init code happens twice on the same page, for logic totally beyond me..

    (once immediately after <!-- ShowImageTVs Plugin :: End -->, once appended to the table which contains the textarea.)

    "<script language="javascript" type="text/javascript" src="/assets/plugins/tinymce3241/jscripts/tiny_mce/tiny_mce.js"></script>
    <script language="javascript" type="text/javascript" src="/assets/plugins/tinymce3241/xconfig.js"></script>
    <script language="javascript" type="text/javascript">
    tinyMCE.init({
    theme : "advanced",
    mode : "exact",
    width : "100%",
    height : "400",
    relative_urls : true,
    document_base_url : "/",
    remove_script_host : true,
    language : "en",
    elements : "tvcontent",
    valid_elements...."

    Help?
    Thanks!

    Edit: SOLVED. Yes, it was the duplicate init that was messing things up. I had copied code blindly for setting up tinymce:

    if (is_array($replace_richtexteditor)) {
    // invoke OnRichTextEditorInit event
    $evtOut = $modx->invokeEvent(’OnRichTextEditorInit’, array(
    ’editor’ => $which_editor,
    ’elements’ => $replace_richtexteditor
    ));
    if (is_array($evtOut))
    echo implode(’’, $evtOut);
    }

    removing the echo implode line fixed the problem.