Xpages 富文本验证 [英] Xpages Rich Text validation

查看:19
本文介绍了Xpages 富文本验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以验证富文本我添加了一个 validateExpression 但它不起作用.

Is there any way to validate a Rich Text I add a validateExpression but is doesn't work.

谢谢

<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>

推荐答案

validatorRequired 是另外必需的,但它本身没有帮助.

The validatorRequired is required in addition but doesn't help on its own.

如果用户点击 RichText 字段并且没有输入任何内容,那么它的内容被设置为

If user clicks into RichText field and doesn't input anything then it's content gets set to

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

空值测试不再有效.

因此,在测试"之前,我们必须使用 replace() 消除它.

So, we have to eliminate this with replace() before we test 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>

正则表达式消除了所有 html 标签 <...>&nbsp; 除了图像标签 和链接标签 .

The regular expression eliminates all html tags <...> and &nbsp; except image tags <img...> and link tags <a...>.

这篇关于Xpages 富文本验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆