Pierre-alexis Krstic
Pierre-alexis Krstic

Reputation: 11

TinyMCE : TypeError: this.getDoc(...) is undefined

my question seems to be already ask, but truth me the situation here is diferent.

Problem: TypeError: this.getDoc(...) is undefined

What i already do: -update jquery version -test every parameters pass to the tinymce functions, everything is ok

My code:

var html = '<div class="traduce-fields"><h4></h4><div class="text-block"><textarea class="textarea-tinymce" id="textarea-' + dataLang + '"></textarea></div><div class="bt-valide-traduce" onclick="sendTraduce($(this))"><p>TO TRADUCE !</p></div></div>';
$('.traduce-bloc-text').find('.traduce-inner').html(html);
//active de nouveau tinyMCE
tinymce.init({selector: '.textarea-tinymce'});
var selector = 'textarea-' + dataLang;
tinymce.get(selector).setContent('ok');

Upvotes: 0

Views: 2186

Answers (2)

Pierre-alexis Krstic
Pierre-alexis Krstic

Reputation: 11

My cod is long and show him in JS fiddle is hard but I got something that could help you:

This code works:

tinymce.init({selector: '.textarea-tinymce'});
alert(tinymce.get(idTextarea));
var tinyMCEInstance = tinymce.get(idTextarea);
tinyMCEInstance.setContent('ok');

This not:

tinymce.init({selector: '.textarea-tinymce'});
/*alert(tinymce.get(idTextarea));*/
var tinyMCEInstance = tinymce.get(idTextarea);
tinyMCEInstance.setContent('ok');

That's very strange, what kind of problem an alert could solve? Thank you for helping me.

Upvotes: 0

Michael Fromin
Michael Fromin

Reputation: 13746

As mentioned in my original comment, my bet is that you are trying to use TinyMCE before its fully initialized. There is a function that can tell you when its fully initialized so you can use that to set the content:

tinymce.init({
  selector: 'textarea',
  ...
  setup: function (editor) {
    editor.on('init', function () {
        this.setContent('Using the on init stuff!');
    });
}

As it takes you time to click on your alert this is probably allowing for TinyMCE to finish loading hence the setContent() call is then working.

Upvotes: 1

Related Questions