Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple tinymce textareas

Tags:

html

tinymce

I use tinymce for a webpage that dynamically generates at least 5 texts.
The configuration I use only works on the first textarea unfortunately.

tinyMCE.init({
    height : "300",
    mode : "exact",
    elements : "content",
    theme : "simple",
    editor_selector : "mceEditor",
    ...

<textarea class="mceEditor" name="content" rows="15" cols="40">content</textarea>

What's the configuration to enable tinymce editing in all textarea's.

like image 912
Udo Avatar asked Mar 19 '13 20:03

Udo


People also ask

How do I reinitialize TinyMCE?

Use tinymce. remove() method to remove TinyMCE editor from the HTML element and again call tinymce. init() on the selector to reinitialize.

Is TinyMCE API key free?

Running TinyMCE from the cloudGet started with a free API key (with a 14-day trial of our premium plugins) and load the TinyMCE package as follows, replacing no-api-key with your own.

Is TinyMCE responsive?

The TinyMCE editor can be made responsive by using css media queries. Simply add css rules that set the width property of table. mceLayout and the tinyMCE textareas.


4 Answers

If you're using "exact" mode you'll need to specify the ids of the elements you wish to convert to editors.

function initMCEexact(e){
  tinyMCE.init({
    mode : "exact",
    elements : e,
    ...
  });
}
// add textarea element with id="content" to document
initMCEexact("content");
// add textarea element with id="content2" to document
initMCEexact("content2");
// add textarea element with id="content3" to document
initMCEexact("content3");

Or, you can use the "textarea" mode, which indiscriminately applies the editor to all textareas.

function initMCEall(){
  tinyMCE.init({
    mode : "textareas",
    ...
  });
}
// add all textarea elements to document
initMCEall();

Just remember that if you're creating textareas dynamically, you will need to call tinyMCE.init() after creating the elements, because they need to be existing for tinyMCE to be able to convert them.

Here is the documentation on modes.

like image 66
DustyWall Avatar answered Oct 22 '22 03:10

DustyWall


For TinyMCE 4.0 you have to use a selector or defining a tinymce.init object/method for each desired configuration (https://www.tinymce.com/docs/get-started/multiple-editors/).

For example, this is a page with 3 editors:

<!DOCTYPE html>
<html>
<head>
  <script src="http://cdn.tinymce.com/4/tinymce.min.js"></script>
  <script type="text/javascript">
  tinymce.init({
    selector: '#myeditable-h1',
    toolbar: 'undo redo'
  });
  tinymce.init({
    selector: '.standard-editor'
  });
  </script>
</head>

<body>
  <form method="post">
    <h1 id="myeditable-h1">This Title Can Be Edited If You Click Here</h1>
  </form>

  <form method="post">
    <div id="myeditable-div1" class="standard-editor">
      <p>This section1 of content can be edited...</p>
    </div>

    <div id="myeditable-div2" class="standard-editor">
      <p>This section2 of content can be edited...</p>
    </div>

  </form>
</body>
</html>
like image 44
Alex Vazhev Avatar answered Oct 22 '22 02:10

Alex Vazhev


You should use different mode in your configuration. For example mode: "specific_textareas" to work for all textarea with a given class which is specified in the editor_selector parameter.

In order to work on all textareas with class mceEditor you can use this:

tinyMCE.init({
    mode : "specific_textareas",
    editor_selector : "mceEditor",
    .....
like image 34
Elena Slavcheva Avatar answered Oct 22 '22 03:10

Elena Slavcheva


use class in selector i have two or more textarea that i want init those with tiny int so

<textarea class="mytextarea"></textarea>
<textarea class="mytextarea"></textarea>
.
.
.

in init tinyint code:

tinymce.init({
    selector: 'textarea.mytextarea',
    plugins : 'advlist autolink link lists preview table code pagebreak',
    .
    .
    .
like image 2
Omid Ahmadyani Avatar answered Oct 22 '22 02:10

Omid Ahmadyani