2015-04-28 279 views
0

我有與此處所述相同的問題:bootstrapvalidator gives "Cannot read property 'group' of undefined" on ckeditor field,但它與ckeditor無關。驗證碼就是從這裏取:http://formvalidation.io/validators/identical/ 這裏是我的jQuery代碼:bootstrapvalidator未捕獲TypeError:無法讀取未定義的屬性'group'

$('form').bootstrapValidator({ 
     framework: 'bootstrap', 
     feedbackIcons: { 
      valid: 'glyphicon glyphicon-ok', 
      invalid: 'glyphicon glyphicon-remove', 
      validating: 'glyphicon glyphicon-refresh' 
     }, 
     fields: { 
      password2: { 
       validators: { 
        stringLength: { 
         min: 6, 
         max: 10, 
         message: 'Field must be 6 to 10 characters long' 
        }, 
        identical: { 
         field: 'password1', 
         message: 'The password and its confirm are not the same' 
        } 
       } 
      } 
     } 
    }); 

這裏是HTML:

 <div class="form-group"> 
      <label class="col-sm-2 control-label">Password</label> 
      <div class="col-sm-10"> 
       <input type="password" name="password1" class="form-control"> 
      </div> 
     </div> 
     <div class="form-group"> 
      <label class="col-sm-2 control-label">Repeat password</label> 
      <div class="col-sm-10"> 
       <input type="password" name="password2" class="form-control"> 
      </div> 
     </div> 

我在這裏完全疊加。請有人幫忙!

回答

0

好的,我讀了文檔。顯然,我使用這個驗證器的方式是錯誤的,因爲文檔是針對較新的(付費)版本,但我有較老的免費版本的bootstrapvalidator。這個驗證器在舊版本中的語法不同:

  password1: { 
       validators: { 
        stringLength: { 
         min: 6, 
         max: 10, 
         message: 'Field must be 6 to 10 characters long' 
        }, 
        identical: { 
         field: 'password2', 
         message: 'The password and its confirm are not the same' 
        } 
       } 
      }, 
      password2: { 
       validators: { 
        identical: { 
         field: 'password1', 
         message: 'The password and its confirm are not the same' 
        } 
       } 
      } 

所以,腳本必須包含兩個選中的字段。

相關問題