How to initialize TinyMCE with Javascript ? [ACF]

15 Views Asked by At

I have an Advanced Custom Fields repeater with a acf-field-wysiwyg as a subfield, with “Delay initialization” activated (tinyMCE only initialize when clicking on the field).

I would like to initialize TinyMCE with JS, not by clicking on the editor itself. The first thing I did was trying to simulate a click on the field but it didn't work so I changed the target (for example '.acf-field-wysiwyg .wp-editor-container') I tried them all, actually, but still no success.

After searching more I have the feeling that a simulated click won't ever work, and found the potential following solution, but it didn't work either.

$('.acf-field-wysiwyg').each(function() {
 var field = $(this),
 editor = field.find('textarea').attr('id');
 // Check if the editor exists and if it has not been initialized already
 if (editor.length && !editor.hasClass('tmce-active')) {
  // Trigger the ACF action to initialize TinyMCE
  field.trigger('acf/setup_fields', [editor]);
 }
});

field.find('textarea').attr('id'); could be incorrect but I tried other targets and still no success.

0

There are 0 best solutions below