4

I get this message : tinyMCE.get("message_data_" + msg_id) is undefined on Firebug after I click on the button to submit the form.

msg_id is defined, I checked it. message_data_ is also defined. The function tinyMCE.get is not for some reason.

3 Answers 3

4

If you are using one single editor instance you may use tinymce.editors[0] instead of tinyMCE.get("message_data_" + msg_id).

Sign up to request clarification or add additional context in comments.

3 Comments

is it supposed to be tinyMCE? And I still cannot fix mine.
tinymce in lowercases is the correct way. you may also use tinymce.activeEditor
To those having this issue, another way of finding out what available tinymce methods (and proper casing for each) is to use firebug to break where you want to call this get method, and explore available functions within the tinyMCE type. Helped me a lot.
1

If you do not have control over init method of TinyMCE then, you can follow this solution. Basically it adds a fallback if TinyMCE is not initialized.

jQuery(document).ready(function($) {

    function myCustomSetContent( id, content ) {
        // Check if TinyMCE is defined or not.
        if( typeof tinymce != "undefined" ) {
            var editor = tinymce.get( id );
            // Check if TinyMCE is initialized properly or not.
            if( editor && editor instanceof tinymce.Editor ) {
                editor.setContent( text );
                editor.save( { no_events: true } );
            } else {
                // Fallback
                // If TinyMCE is not initialized then directly set the value in textarea.
                //TinyMCE will take up this value when it gets initialized.
                jQuery( '#'+id ).val( text );
            }
            return true;
        }
        return false;
    }

    function myCustomGetContent( id ) {
        // Check if TinyMCE is defined or not.
        if( typeof tinymce != "undefined" ) {
            var editor = tinymce.get( id );
            // Check if TinyMCE is initialized properly or not.
            if( editor && editor instanceof tinymce.Editor ) {
                return editor.getContent();
            } else {
                // Fallback
                // If TinyMCE is not initialized then directly set the value in textarea.
                // TinyMCE will take up this value when it gets initialized.
                return jQuery( '#'+id ).val();
            }
        }
        return '';
    }

    $(".class-to-update-content").on("click", function(e) {
        myCustomSetContent( "tinymce-editor-id", "New Content in Editor" );
    });

    $(".class-to-get-content").on("click", function(e) {
        $("div.class-to-display-content").html( myCustomGetContent( "tinymce-editor-id" ) );
    });
});

Ref : http://blog.incognitech.in/tinymce-undefined-issue/

Comments

0

if you are using multiple editor in a form then you can create a function and get its value i.e.

// Declare a function to get editor value
function tinyMca_text(field_id) {

 if ( jQuery("#"+field_id+":hidden").length > 0)
 {
 return tinyMCE.get(field_id).getContent();
 }
 else
 {
  return jQuery('#'+field_id).val();
 }

}

// show that value

console.log(tinyMca_text('field'));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.