Xpages Rich Text validation

Is there a way to check Rich Text, I add validateExpression, but it does not work.

thanks

<xp:inputRichText value="#{document1.Request}" id="inputRichText1" style="width:99.0%"> <xp:this.validators> <xp:validateExpression message="Attachment is missing"> <xp:this.expression><![CDATA[#{javascript: if(getComponent("inputRichText1").getSubmittedValue()!== ''){ return true }}]]></xp:this.expression> </xp:validateExpression> </xp:this.validators></xp:inputRichText> 
+1
source share
2 answers

validatorRequired is required additionally, but alone does not help.

If the user clicks on the RichText field and does not enter anything, the content gets the value

 <p dir="ltr"> &nbsp;</p> 

and the test for an empty value no longer works.

So, we have to fix this with a replacement () before we check for ".".

 <xp:messages id="messages1" /> <xp:inputRichText value="#{document1.Request}" id="inputRichText1" style="width:99.0%" disableClientSideValidation="true"> <xp:this.validators> <xp:validateExpression message="Attachment is missing"> <xp:this.expression><![CDATA[#{javascript: var text = (value + " ").replace(/(<((?!img|a\s)[^>]+)>)|&nbsp;/ig, "").trim(); return text !== ""; }]]></xp:this.expression> </xp:validateExpression> <xp:validateRequired message="Attachment is missing" /> </xp:this.validators> </xp:inputRichText> 

Regular expression excludes all html <...> and &nbsp; except for image tags <img...> and link tags <a <a...> .

+5
source

For standard components, I know that validators are only launched if there is also a mandatory validator. Basically, if you want the content to meet specific criteria, it is suggested that you also need to check that the field is not empty.

+1
source

Source: https://habr.com/ru/post/910409/


All Articles