thefrozencoder

Programming and Technology blog

TinyMCE, ASP.NET and validation

The following describes how to use a custom validator function along side TinyMCE to validate the contents of the textarea.

Add the custom validator and setup the properties as you normally setting the ControlToValidate to the ID of the textarea and the ClientValidationFunction to the function name you see below (this can be changed of course).

The key is to call TinyMCE's triggerSave() method so the editor can synch up to the underlying textarea. Once this is done the textarea now has content.

<script language="JavaScript" type="text/javascript">
function validateTinyMCEText(source, args) {   
var txt = document.getElementById(source.controltovalidate);
tinyMCE.triggerSave();
args.Value = (txt.value.replace(/^W+/,'')).replace(/W+$/,'');
args.IsValid = (args.Value != '');}
</script>

Hopefully this will help out a few people
Comments are closed