I have an HTML form with a few fields. One of them is a textarea managed by CKEditor.
When the user wants to submit the form, I want to check whether he entered values
We use prototype, with that library and the following addition:
Element.addMethods({
getInnerText: function(element) {
element = $(element);
return element.innerText && !window.opera ? element.innerText
: element.innerHTML.stripScripts().unescapeHTML().replace(/[\n\r\s]+/g, ' ');
}
});
(Thanks to Tobie Langel)
I was able to use the following function to determine whether any actual text was inside CKEditor:
function editorEmpty(instanceName){
var ele = (new Element('div')).update(CKEDITOR.instances[instanceName].getData());
return (ele.getInnerText() == '' || innerText.search(/^( )+$/i) == 0);
}
Note the test for
as well - often when the editor appears empty, it actually contains something like:
.