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