Sachin
Sachin

Reputation: 3782

How to access the hidden input field which TinyMCE uses for text editor

I am creating an application where I am using the TinyMCE editor to provide the text editing options in the text area. I want to provide a save feature where I want to save the textarea content using AJAX post.

So on button click I am using form.serialize() to send it in the AJAX request. Below is the jquery that I am using. According to this, it should serialize all the fields which are set except the one name csrfmiddlewaretoken. The id of the textarea is id_text which is given by django models. However the problem is whatever text I type in the editor is not actually copied onto my textarea.

Most probably TinyMCE editor displays it on the screen and only when we press the submit button, does it copy over to the underlying textarea. Because of this I am not able to save the content which is being typed in.

$(".preview_button").click(function() 
    {           
        $.ajax({
          type: "POST",
          url: current_link,
          data: $("#blog_form :input[name!='csrfmiddlewaretoken']").serialize(),
          dataType: 'json',
          success: function(data) 
          {
            var preview_link = location.host;
            preview_link = preview_link + data;
            window.open(data,'preview_tab');
            $("#reply-message").html('Form saved' + $("#blog_form :input[name!='csrfmiddlewaretoken']").serialize());
          },
          error: function(request,error) 
          {
            // display success message and reset values in the form fields
            $("#reply-message").html('Form not saved because error:' + error);
          },

        });

        return false;   
    });

Can anybody tell me how to access the text in the TinyMCE text editor, which is as shown on the screen.

Upvotes: 1

Views: 2318

Answers (3)

benjaoming
benjaoming

Reputation: 2215

Use the save method on the Editor instance to move contents from the Editor to the textarea.

Upvotes: 2

Lakhan
Lakhan

Reputation: 13226

Add this tinyMCE.triggerSave(); like that way :

tinyMCE.triggerSave();
$.ajax({
// Your code
});

It will resolved your issue.

Upvotes: 0

Abid A
Abid A

Reputation: 7858

You can use the getContent function: http://www.tinymce.com/wiki.php/API3:method.tinymce.Editor.getContent

Upvotes: 2

Related Questions