Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
15 lines (10 sloc) 1009 Bytes

jQuery validation and TinyMCE

Just solved a problem where the jQuery validation plugin wasn't playing so nicely with TinyMCE -- the validation plugin was trying to validate the textarea before TinyMCE had a chance to copy the editor contents back to the textarea. I was about to yank TinyMCE out of the page but a little reading through the TinyMCE docs led me to try this:

{% codeblock lang:javascript %} $('#mySubmitButton').click(function() { var content = tinyMCE.activeEditor.getContent(); // get the content $('#myTextarea').val(content); // put it in the textarea });

$('#myForm').validate(); {% endcodeblock %}

And what do you know, it works. One note: it's important to bind the content replacement to the click event of the submit button, not to the actual form submission, or else the validation may try to run before the content gets copied back to the textarea.