Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving multiple TinyMCE instances

I have multiple instances of TinyMCE on one page.

I have a javascript autosave running in the background that automatically saves the forms in the database via a POST request. This works good with one form where I can set the element ID in the init. However, in my scenario, the user can have a variable number of TinyMCE forms, so having multiple hardcoded element ID's do not seem practical.

TL;DR: Dynamically grab all instances of TinyMCE in the same page without knowing the instance ID. Or, any other approach to save multiple forms in one auto_save() function.

like image 687
stan Avatar asked Jul 02 '11 23:07

stan


1 Answers

The way Brett decribed is correct. Here is the code you may call whenever needed, i.e. in your auto_save() function:

for (var i = 0; i < tinymce.editors.length; i++) {
    // you need to do what is needed here
    // example: write the content back to the form foreach editor instance
    tinymce.editors[i].save();
}
like image 68
Thariama Avatar answered Sep 29 '22 13:09

Thariama