Reputation: 43
Platform : Domino v9
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.
<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>
I tried the solution mentioned in Tommy Valand's blog but that did not solve the problem. Tommy's Blog
How do I validate the RichText control without losing the new content ?
Upvotes: 2
Views: 392
Reputation: 3395
Strange behavior. Maybe you can validate your RTF control via CSJS (and not SSJS/Java) with this recently added snippet: http://openntf.org/XSnippets.nsf/snippet.xsp?id=validate-rich-text-field
Upvotes: 2
Reputation: 868
When I have complex validation, I sometimes use a hidden input field for validation. Not sure if this will help in this situation, but could be worth a try..
getLocalValue should return the converted value in the validation phase. Since you're dealing with strings, getSubmittedValue might be even more appropriate/easier to use.
If you use xp:message, set the for attribute to whatever id you decide for the hidden field.
<xp:inputHidden id="dummyValidatorField" value="dummyValue">
<xp:this.validators>
<xp:validateExpression>
<xp:this.expression><![CDATA[#{javascript:var contentStr = getComponent( 'idOfRtField' ).getLocalValue(); // maybe you need to append .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>
Upvotes: 3