Saturday, June 1, 2024
 Popular · Latest · Hot · Upcoming
31
rated 0 times [  35] [ 4]  / answers: 1 / hits: 45503  / 13 Years ago, thu, january 5, 2012, 12:00:00

I need to validate a form. This form has some dropdowns and tinyMCE editor, I am validating this form by appending the string Required after each field if it is blank, However I am unable to validate the tinyMCE editor, if the editor is blank, I tried something like



tinyMCE.get('tinyedotor').getContent();


but no luck.



here is my fiddle


More From » jquery

 Answers
44

getContent() should work just fine. Your fiddle doesn't contain the form validation code for the editor value, which is quite crucial here. Try this:



var editorContent = tinyMCE.get('tinyeditor').getContent();
if (editorContent == '')
{
// Editor empty
}
else
{
// Editor contains a value
}


Forked fiddle



Also note you've declared multiple id's for your select drop-down.



Edit: You can get the id of the editor container with the getContainer() method: tinyMCE.get('tinyeditor').getContainer(). Inserting an error message after the editor would then be something like this:



$('<span class=error>Editor empty</span>').insertAfter($(tinyMCE.get('tinyeditor').getContainer()));


This, however, will create a new span each time the user clicks the submit button, so you'll probably want to have an error message container with a unique id and check if the container already exists before inserting it.



Edit 2: Updated fiddle.


[#88206] Wednesday, January 4, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hadens

Total Points: 142
Total Questions: 98
Total Answers: 100

Location: Kenya
Member since Mon, Jun 14, 2021
3 Years ago
;