BootstrapValidator不能使用xpages吗?

时间:2017-01-25 16:23:34

标签: xpages bootstrapvalidator

我是bootstrap的初学者,我试图使用BootstrapValidator构建一个Xpage来验证inputText,但它不起作用,在代码源下面,我们可以帮助我找到解决方案!

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
    xmlns:xc="http://www.ibm.com/xsp/custom">
   <xp:this.resources>
   <xp:styleSheet href="/bootstrapValidator/css/bootstrap.css"></xp:styleSheet>
   <xp:styleSheet href="/bootstrapValidator/css/bootstrapValidator.css"></xp:styleSheet>
   <xp:script src="/JQueryXSnippet.js" clientSide="true"></xp:script>
   <xp:script src="/bootstrapValidator/js/bootstrap.min.js" clientSide="true">  </xp:script>
   <xp:script src="/bootstrapValidator/js/bootstrapValidator.js" clientSide="true"></xp:script>
    </xp:this.resources>
                <div class="col-md-5">
                <xp:inputText id="username" title=" username"></xp:inputText>
</div>

<xp:scriptBlock id="scriptBlock1">
<xp:this.value><![CDATA[$(document).ready(
function() {
        $("#{id:username}" ).bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            username: {
                message: 'The username is not valid',
                validators: {
                    notEmpty: {
                        message: 'The username is required and can\'t be empty'
                    },
                    stringLength: {
                        min: 6,
                        max: 30,
                        message: 'The username must be more than 6 and less than 30 characters long'
                    },
                    regexp: {
                        regexp: /^[a-zA-Z0-9_\.]+$/,
                        message: 'The username can only consist of alphabetical, number, dot and underscore'
                    }
                }
            } } });
              ]]></xp:this.value>
</xp:scriptBlock>

          </xp:view>

1 个答案:

答案 0 :(得分:3)

使用XPages compatible jQuery selector x$代替原生jQuery $ selector。

另请尝试使用XSP.addOnLoad()代替(document).ready()

此外,名为“username”的XPage xp:inputText字段在浏览器中有一个名为“view:_id1:_id2:_id8:username”的ID。因此,它不会被称为“用户名”,如bootstrapValidator的字段定义中所述。因此bootstrapValidator无法找到该字段。尝试将此添加到您的scriptBlock而不是"username: {"

#{id:username}: {