Welcome to WebmasterWorld Guest from 174.129.151.95

Forum Moderators: open

Message Too Old, No Replies

TinyMCE textarea validation

   
7:19 pm on Nov 17, 2011 (gmt 0)



Hello everyone,

I came across the need of using a rich text editor, I ended up choosing TinyMCE, it works real nice but no matter how much I've tried I can't get to validate the data prior to submitting it.

All I want is to make sure the textarea (which I believe is no longer a textarea since TinyMCE converts it into some other elements) is not empty, I have tried several examples on their forum with no luck so I'm trying my luck here.

Has anyone dealt with this issue? Thanks.
12:26 pm on Nov 27, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



You could use the getContent and check if the content is empty.
[tinymce.com...]

So you hook the submit button and check if there is any content before allowing or setting the form action.
7:07 pm on Jan 2, 2012 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



And if you have more than one instance of the editor running you may want to use the triggerSave() method:

[tinymce.com...]

If you want to focus on any element after realizing it is empty you can use the execCommand:

[tinymce.com...]
[tinymce.com...]

pseudocode example:
if (your textarea has an error) { 
tinyMCE.execCommand('mceFocus', false, 'textareaID');
return false;
}