Welcome to WebmasterWorld Guest from 54.198.205.161

Forum Moderators: open

Message Too Old, No Replies

TinyMCE textarea validation

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

Junior Member

5+ Year Member

joined:June 18, 2010
posts: 167
votes: 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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 30, 2007
posts:1394
votes: 0


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)

Administrator

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

joined:July 31, 2003
posts:12547
votes: 2


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;
}