Forum Discussion

Akenefick's avatar
Akenefick
Genius
4 years ago

Preloaded Text In Tinymce Editor

I am trying to create a component to add to the PostPage that will prefill the text editor with some questions to answer when posting an idea. I tried using this 

tinymce.activeEditor.setContent("<p>Test Question One<br><br><br>Test Question Two</p>");

 I also tried

document.getElementById("tinymce").innerHTML = "<p>Test Question One<br><br><br>Test Question Two</p>";

 

I tried saving a .js file to "Other Assets" so I could "defer" the execution until after the page loads in case that was the issue.

I found this great post Default template for suggesting an idea in Idea Ex... - Atlas (khoros.com) by PerBonomi and tried to use his code minus the category check.

In every case the editor remains blank. Any idea where I might be going wrong? Thanks

  • This is probably what you are looking for.

    tinyMCE.get('tinyMceEditor').execCommand('mceInsertContent', false, '<p>Test Question One<br><br><br>Test Question Two</p>');

    Keep in mind that this will only work after the editor has initialized properly. Good way to ensure is by wrapping it like that so that it will run once the Khoros jQuery object is present:

    <@liaAddScript>
      ;(function($) {
        tinyMCE.get('tinyMceEditor').execCommand('mceInsertContent', false, '<p>Test Question One<br><br><br>Test Question Two</p>');
      })(LITHIUM.jQuery);
    </@liaAddScript>
  • This is probably what you are looking for.

    tinyMCE.get('tinyMceEditor').execCommand('mceInsertContent', false, '<p>Test Question One<br><br><br>Test Question Two</p>');

    Keep in mind that this will only work after the editor has initialized properly. Good way to ensure is by wrapping it like that so that it will run once the Khoros jQuery object is present:

    <@liaAddScript>
      ;(function($) {
        tinyMCE.get('tinyMceEditor').execCommand('mceInsertContent', false, '<p>Test Question One<br><br><br>Test Question Two</p>');
      })(LITHIUM.jQuery);
    </@liaAddScript>
    • Akenefick's avatar
      Akenefick
      Genius

      Hey Claudius, now that I have these questions preloaded into the editor the cursor moves to the line after the last question, which makes sense. Do you know of a way to position the cursor, so I could move it to the line after the first question?

      Thanks