Support

Account

Home Forums ACF PRO insert values into fields programmatically Reply To: insert values into fields programmatically

  • Adding actions to tinyMCE editors.

    I kept digging and I figured out how to add actions to the editors. This needs to be done only after the editor is added with the new “delay initialization” feature of wysiwyg fields.

    
    jQuery(document).ready(function($){
      
      tinyMCE.on('addEditor', function(e) {
        // fires every time an editor is initialized
        if (typeof(e.editor) == 'undefined' || !e.editor.id.match(/^acf-editor-/)) {
          // not an acf wysiwyg field
          return
        }
        console.log(e.editor); // the editor
        console.log(e.editor.id); // the editor id
        e.editor.on('input', function(ed) {
          // fires on any input to this editor
          // could also use change, blur, focus, etc...
          // you'd want to check the editor ID to match it
          // to only the one you want to add this action to
          console.log('input');
        });
      }); // end tinyMCE.on
      
    }); // end jQuery(document).ready