I've a list of elements editable via a simple AJAX/jQuery edit button, which works great. But when I try editing the same field a second time it doesn't want to play ball.
Code snippets
var content = tinyMCE.get('content').getContent(); //get tinyMCE content
$("#edititem").load("editItem.php", {content: content}); //jQuery post
Solution - this is how I got it working:
EDIT - when editing, add the tinyMCE control to the textarea
tinyMCE.execCommand("mceAddControl",true,'content');
SAVE - when saving, remove the control for next time
tinyMCE.execCommand('mceRemoveControl',false,'content');
Just thought I'd add a workaround solution that works in combination with the solution above:
setTimeout(function() {tinyMCE.execCommand("mceAddControl", true, "content");}, 5);
For whatever reason, I'm not sure if it's a timing issue with the DOM manipulation or something else, but a tiny delay makes life better. However the setTimeout()
did NOT work in combination with using a jQuery .each()
method, such as:
$("textarea").each(function(index) {
tinyMCE.execCommand("mceAddControl", false, $(this).attr("id"));
});
That must be a whole different timing issue.
Anyhoo, thought I'd share these findings as I'm sure others and even possibly me again will find this posting helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With