2015-09-29 70 views
0

我使用JQuery和BootstrapValidator 0.5.2進行表單驗證(此刻我堅持使用舊版本)。 我想驗證Ace編輯器字段(http://ace.c9.io),它不能爲空。 驗證工作正常,問題是我無法手動更新字段驗證狀態。 任何人都知道如何訪問Ace編輯器字段的引導驗證功能? 基本上我的代碼如下:BootstrapValidator&Ace Editor:手動更新驗證狀態

<div id="text" name="text" class="ace-editor" data-bv-field="text"></div> 

$('#form').formValidation({ 
    fields: { 
     'text': { 
      validators: { 
      callback: { 
       // check content of ace editor 
       message: 'Mandatory', 
       callback: function(value, validator) { 
        var editor = ace.edit('text'), 
         ok = (editor.session.getValue() != ''), 
         status = (ok) ? 'VALID' : 'INVALID'; 

        // gives error: $(...).data(...) is undefined 
        //$('#text').data('bootstrapValidator').updateStatus('text', status, null); 

        // gives error TypeError: this.options.fields[b] is undefined in bootstrapValidator.min.js 
        $('#text').bootstrapValidator().data('bootstrapValidator').updateStatus('text', status, null); 

        return ok; 
       } 
      } 
     } 
    } 
}); 

回答

0

這條線:

$('#text').data('bootstrapValidator').updateStatus('text', status, null); 

應該是:

$('#form').data('bootstrapValidator').updateStatus('text', status, null); 

的第一個參數應該是形式,而不是你的元素更新。希望這可以幫助。