When would you want to validate it? Like with a normal text input in a normal form, you would assign an onchange, onblur, and/or onkeyup, etc. event to the input and then check its value against one or more tests of one kind or another. Sometimes you don't even bother validating until the form is submitted. That would be the easiest here. On the demo.htm there is already an onsubmit function that accesses the value of the hidden rte1 input that the script generates and places in the form:
Code:
<form name="RTEDemo" action="demo.htm" method="post" onsubmit="return submitForm();">
<script language="JavaScript" type="text/javascript">
<!--
function submitForm() {
//make sure hidden and iframe values are in sync before submitting form
//to sync only 1 rte, use updateRTE(rte)
//to sync all rtes, use updateRTEs
updateRTE('rte1');
//updateRTEs();
alert("rte1 = " + document.RTEDemo.rte1.value);
//change the following line to true to submit form
return false;
}
//Usage: initRTE(imagesPath, includesPath, cssFile)
initRTE("images/", "", "");
//-->
</script>
After a little extra typing in the editor, so that it shows:
here's the "
preloaded content"
Hola!
Bob. ahh
This hidden input's value is:
here's the "<em>preloaded</em> <b>content</b>"<br>Hola!<span style="font-weight: bold;"> Bob.</span> ahh<br>
The DOM node of this script generated hidden input is seen by the browser as:
HTML Code:
<input id="hdnrte1" name="rte1" value="
here's the "<em>preloaded</em> <b>content</b>"<br>Hola!<span style="font-weight: bold;"> Bob.</span> ahh<br>" type="hidden">
All that's just to give you a rough idea of what's going on. So to answer your question, you could do something like so (there are many possible variations) for the submitForm function:
Code:
function submitForm() {
//make sure hidden and iframe values are in sync before submitting form
//to sync only 1 rte, use updateRTE(rte)
//to sync all rtes, use updateRTEs
updateRTE('rte1');
//updateRTEs();
if(isValid(document.RTEDemo.rte1.value)){
return true;
}
alert('Please Follow the Required Input Parameters.');
return false;
}
In this particular approach, the isValid function would be your validation routine that returns true if the value passes, false otherwise. If the value of the hidden field passes, the form submits, otherwise the alert is popped.
The crucial thing to know though is that the value will contain the tags (unseen to the user except for their effect on the appearance of the text in the editor), something like as stated above:
here's the "<em>preloaded</em> <b>content</b>"<br>Hola!<span style="font-weight: bold;"> Bob.</span> ahh<br>
So you will have to allow these tag and attribute characters in your validation routine.
What do you want to validate the content to? What sort of rules were you thinking of imposing on it?
Bookmarks