2017-01-25 5 views
1

私はブートストラップの初心者ですが、私はBootstrapValidatorを使ってinputTextを検証するためにXpageをビルドしようとしていましたが、コードソースの下で動作しませんでした。BootstrapValidatorはxpagesで動作しませんか?

<?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> 
+0

のエラーを追加してください。どういう場合にエラーが報告されますか? –

+0

Oliver Busseさんに感謝します。でも、私はJavaスクリプトコンソールをチェックしても何のエラーもありません! – user7329277

答えて

3

代わりにネイティブjQueryの$セレクタのXPages compatible jQuery selector x$を使用してください。

(document).ready()の代わりにXSP.addOnLoad()も試してみてください。

さらに、XPageの「username」というxp:inputTextフィールドには、ブラウザに「view:_id1:_id2:_id8:username」のような名前のIDがあります。したがって、bootstrapValidatorのフィールド定義に記載されているように、「username」と呼ばれることはありません。したがって、bootstrapValidatorはフィールドを見つけることができません。あなたのscriptBlockに"username: {"の代わりに

#{id:username}: { 
+0

Henrik Laustenさん、ありがとうございました。私は関数を変更し、jqueryをインストールしたXPage用のx $ jQueryセレクターを使用しました。<![CDATA [ XSP.addOnLoad(function(){ x $ " {id:username} ")。bootstrapValidatorしかし、それでもテキストの検証が機能しないのと同じ問題です。 – user7329277

+0

次の問題は、おそらくbootstrapValidator設定の" username: "への参照です。フィールドの正しいクライアント側の名前 –

+0

私はこのチュートリアルに従っていますhttp://twitterbootstrap.org/bootstrap-form-validation/ imはクライアント側の名前が何を意味するのか理解していませんか? – user7329277

関連する問題