Forum closed. New forum available at http://community.wymeditor.org/

Dynamically add WYMEditors

Support forum for WYMeditor.

Dynamically add WYMEditors

Postby ionutvalean on Mon Aug 31, 2009 11:50 am

Hi,
I am pretty new to JavaScript and JQuery and I want to integrate the WYMEditor in a page. I want to do this dynamically by giving the user the possibility of having more then one WYMEditor or none. I am trying to do this like so:
I have a snippet that I will always clone and only change it's text property.

The snippet declaration

Code: Select all
<div id="wymEditorSnippet" class="WymEditorBlock" style="WIDTH:100%">
   <textarea id="wymEditor" class="wymeditor"></textarea>
</div>


The Add function

Code: Select all
function AddWymEditorBlock(structure){
   var snippet = $("#wymEditorSnippet").clone();
        snippet.find("#wymEditor").val(structure.html);
   return snippet;
}


The problem is that when the page is loaded, the JavaScript that replaces all objects that has [class="wymeditor"] with the WYMEditor controls. When I clone the snippet, I clone the entire WYMEditor, with the html of the first cloned object. The real problem is that those "blocks" added after page load do not work properly.

Please give me a hand with this, so I could have blocks that work properly, dynamically added.
ionutvalean
 
Posts: 3
Joined: Mon Aug 31, 2009 11:30 am

Re: Dynamically add WYMEditors

Postby mr_lundis on Mon Oct 05, 2009 3:03 pm

Hello ionutvalean, and welcome to the forum!
Cloning the entire form won't work as you already know. I would create a completely new instance of the whole form, but if you for some reason can't do that try removing the cloned WYMeditor markup instead. When you got the form in place create a new instance of the editor to convert the new/cloned textarea into an editor.

Cheers! ;)
Jonatan Lundin - designer, developer and forum moderator. You should follow me on Twitter!
mr_lundis
 
Posts: 335
Joined: Sun Dec 02, 2007 10:59 am
Location: Sweden

Re: Dynamically add WYMEditors

Postby ionutvalean on Mon Oct 19, 2009 1:31 pm

Hi mr_lundis,

Thanks for the reply.
I had managed to make it work. I left the snippet like that and when I needed a new instance of the WYMEditor I just cloned the snippet and run the WYMEditor initializer on that clone.
On top of that I needed to know what was it's instance number, so I made a hidden span in the snippet that kept the WYMeditor.INSTANCES.length. With that I can refer to it at any time.

Cheers
ionutvalean
 
Posts: 3
Joined: Mon Aug 31, 2009 11:30 am


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests