How do I initialize TinyMCE on a ajax loaded textarea in 4.x?

血红的双手。 提交于 2019-11-29 05:55:42
Arquimedes de Siracusa
tinymce.remove();
tinymce.init();

This works well!

In TinyMCE 4.x mceRemoveControl and mceAddControl have been removed. You have to use mceRemoveEditor and mceAddEditor instead.

Got it from: [Resolved] mceRemoveControl and mceAddControl in tinymce 4

Otherwise, you can reload tinymce.init({ ... }) but that should not be the way as it would be slower.

You can load TinyMCE after including textarea with the following code:

//initialize tinyMCE in page
tinymce.init({selector:'textarea'});

just for then running into the same problem.

I solved the problem with wrapping the init Script into a function like this.

in my init.js file

initializeTinyMce();
function initializeTinyMce(selector){
  if(selector == undefined){selector = 'textarea';}
  ...
  tinymce.init({
    selector: selector,
    ...
  });
}

so on your ajax request result you add

<script type="text/javascript">
  $(document).ready(function(){
    initMCE('textarea#someId');
  });
</script>

works fine for me

tinymce.init({ selector:'textarea' });

just use this in ajax and if you are not able to pick the value then Before submitting the form, call

tinyMCE.triggerSave();

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!