开发者

TinyMCE submits blank value when I try to use multiple configurations

I am using TinyMCE to create a WYSIWYG editor in my webapp. I need to configure it in advanced mode for some textarea's and in simple mode for some. I am configuring TinyMCE like this.

<head>
    <script type="text/javascript">
        tinyMCE.init({
            mode : "textareas",
            theme : "simple",
            editor_selector : "simple"
        });

        tinyMCE.init({
            mode : "textareas",
            theme : "advanced"
        });              
    </script>
</head>

This configuration works and shows me TinyMCE in simple or advanced mode, based on the class of the textarea.

However, the problem happens when I submit a form. The server gets a blank for the textarea. (this problem does not occur when I use only one configuration for TinyMCE)

I did some searching and came across a suggestion whi开发者_如何学编程ch said I should explicitly ask TinyMCE to save the content before doing a submit. I tried adding this code to my form.

$('#postFeedback').click( function(){
    tinyMCE.triggerSave(true,true);
    alert("TextArea val - " + $('input[name=email]').val() + "- " + $('textarea.simple').val());
    $('form').submit();
});

The form does get submitted, but I have the same problem. The value in the textarea is blank. I also put an alert (as shown above) to check the value of the textarea, and it is indeed blank.

Some questions to start with:

  • TinyMCE works perfectly well, when I have just one configuration (init). However, it gets messed up the momnent I have two? Any clue why this might happen?
  • Is it necassary to explicitly ask TinyMCE to save the textarea contents?
  • How do I begin debugging this problem?


You should initialize your editors using mode: "exact", in your inits. Then you are able to initialize a single tinymce instance using

tinyMCE.execCommand('mceAddControl', false, editorid); //editorid should be the id of the textarea

and the configurations of your inits will be aplied (I somehow got the feeling there is something pretty bad using two inits for all the tinymce editors (because it looks they get both called for all of them)).

EDIT: In order to be able to use different inits you should call mceAddControl using an initialization_object instead of an editor id only. Example:

var config_tinymce_xy = {

    mode: 'exact',
    theme: "advanced",
    content_css : "my.css",
    plugins: "code,...",

    theme_advanced_buttons1 : "code,...",
    theme_advanced_buttons2 : "...",
    ...

};

var config_tinymce_xy2 = {

    mode: 'exact',
    theme: "simple",
    content_css : "my.css",
    ...
};

init_obj = {element_id:'my_editor_id', window: window};
$.extend(true, init_obj, config_tinymce_xy);
tinyMCE.execCommand('mceAddFrameControl',false, init_obj);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜