Platform : Domino v9
Background:
When an user opens a document using an Xpage, the Rich Text control (CKEditor)displays the existing content in that document.
The RichText field is bound to a backend Notes document.
When an user makes any changes to this content and clicks the Update button, validation occurs (for this example, we are checking to see if length exceeds 20 characters).
Validation is done using the ValidateExpression option.
On validation, user sees the error message but the new content entered by user is lost. The Rich Text control displays the original content.
Validation Code
<xp:this.validators>
<xp:validateExpression>
<xp:this.expression><![CDATA[#{javascript:var contentStr = value.getContentAsText();
var regex = /(<([^>]+)>)/ig ;
contentStr = contentStr.replace(regex,'');
if( contentStr.length < 20 ) {
return true;
}else{
return false;
}
}]]></xp:this.expression>
<xp:this.message><![CDATA[#{javascript:var errMsg = getErrorMessageText ('713','');
if ( errMsg != null && errMsg != "") {
//return errMsg;
return "Length cannot exceed 20 characters";
}else{
return "Length cannot exceed 20 characters";
}}]]></xp:this.message>
</xp:validateExpression>
</xp:this.validators>
Things I tried:
I tried the solution mentioned in Tommy Valand's blog but that did not solve the problem. Tommy's Blog
Question
How do I validate the RichText control without losing the new content ?