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

WYMeditor creating new instances every time

Support forum for WYMeditor.

WYMeditor creating new instances every time

Postby rwt on Sat Aug 01, 2009 11:32 pm

Hello all.
I've been in a deep pit for hours here.
I'm using ajax to create a form with two WYMeditor boxes. Then ajax to send the form. If theres an error, the form is displayed again. fairly simple
Now here's my problem. Whenever the form is created again, WYMeditor creates a new instance. I tried deleting the instances beforehand, updating, etc… nothing works.
First I thought the update wasn't working. Because when I submitted the page, it worked the first time, then kept the same values the next times.
Then looking at the DOM with Firebug, I saw that the iframe WYMeditor instances where actually adding up. 1,2,3,4,5,6,7 etc…
What a pain!!
Why?? I replace the content of the parent div with ajax, so why?

Code: Select all
$('input#submit').click(function(e){
   e.preventDefault();
   
   var wym1 = jQuery.wymeditors(0);
   var wym2 = jQuery.wymeditors(1);
   
   var fid = $(this).attr('title');
   var fcat = $(this).siblings('select#catid').children('option:selected').attr('value');
   var fpar = $(this).siblings('#parent').val();
   
   $.ajax({
      type: "POST",
      url: "ajax.php",
      cache: "no-cache",
      data: ({
         ed : fid,
         edcat : fcat,
         edpar : fpar,
         edshort : wym1.html(),
         edlong : wym2.html(),
      }),
      beforeSend: function(){
         jQuery.each(WYMeditor.INSTANCES, function() {
            this.update();
            delete this;
         });
      
      },
      success: function(html){
         $('#box fieldset').html(html);
         ajax();
      },
   });
});


Is it normal? How do I prevent it? Please help.

Cheers,
rwt
jQuery 1.3.2
WYMeditor 0.5rc1
User avatar
rwt
 
Posts: 3
Joined: Sat Aug 01, 2009 11:22 pm
Location: Switzerland

Re: WYMeditor creating new instances every time

Postby rwt on Tue Aug 04, 2009 1:37 pm

bump ?
jQuery 1.3.2
WYMeditor 0.5rc1
User avatar
rwt
 
Posts: 3
Joined: Sat Aug 01, 2009 11:22 pm
Location: Switzerland

Re: WYMeditor creating new instances every time

Postby rwt on Tue Aug 04, 2009 10:31 pm

wohoo!! I found my answer… so freaking simple!!!

After havin loaded my ajax, I execute this line:

Code: Select all
WYMeditor.INSTANCES = WYMeditor.INSTANCES.slice(3);


It works because I know how many INSTANCES I have. Otherwise you would need to save the number in a var like this:
Code: Select all
var wymlenght = WYMeditor.INSTANCES.lenght;

Then add after ajax call:
Code: Select all
WYMeditor.INSTANCES = WYMeditor.INSTANCES.slice(wymlenght);


Then EVERYTHING (and I mean everything) worked!! yee-haa!
Note: Don't forget to update the editors beforehand.

Pour les francophones qui captent vraiment pas l'anglais, et qui auraient un problème d'accumulation d'instances, utilisez la ligne de code cité au dessus.
jQuery 1.3.2
WYMeditor 0.5rc1
User avatar
rwt
 
Posts: 3
Joined: Sat Aug 01, 2009 11:22 pm
Location: Switzerland

Re: WYMeditor creating new instances every time

Postby Nico on Mon Aug 17, 2009 9:49 am

Hi,

Your solution is strange.

You have an array. You get the length of this array, and than you slice this array, starting after the end of the array.
So of course you'll always get an empty array. This is how the "slice" method works.

Why not simply create a new array, the result is exactly the same, and it's really simpler, no ?

so you should just do :

Code: Select all
WYMeditor.INSTANCES = [];


And that's all, it should work exactly the same.

Nico
Nico
 
Posts: 19
Joined: Tue Jun 23, 2009 6:49 pm


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron