使用bootstrap中的bootstrapValidator,驗證ckeditor富文本框不為空


引入js

 <script src="/components/ckeditor/ckeditor.js" type="text/javascript"></script>
   <script src="/components/ckeditor/adapters/jquery.js" type="text/javascript"></script>

1.jsp頁面

  <textarea id="moduleDescribe" name="moduleDescribe"></textarea>

2,js

$('#moduleForm').bootstrapValidator({
      message: '此值沒有被驗證',
     //excluded:[":hidden",":disabled",":not(visible)"] ,//bootstrapValidator的默認配置
      excluded: [':disabled'],    //關鍵配置,表示只對於禁用域不進行驗證,其他的表單元素都要驗證
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
    fields: {/*驗證:規則*/                           
        moduleDescribe: {//驗證input項:驗證規則
              message: '此描述無效',               
              validators: {
                  notEmpty: {//非空驗證:提示消息 message: '詳情介紹不能為空' }
              }
          }
    }
})
.on('success.form.bv', function(e) {//點擊提交之后
      // Prevent form submission
        e.preventDefault();
        // Get the form instance
        var $form = $(e.target);
        // Get the BootstrapValidator instance
        var bv = $form.data('bootstrapValidator');
        // Use Ajax to submit form data
        //此處調用提交方法
        
         
})
.find('[name="moduleDescribe"]').ckeditor().editor.on('change', function(){ $('#moduleForm').bootstrapValidator('revalidateField', 'moduleDescribe'); });

標記為紅的地方,都為驗證富文本編輯器所必須要的代碼(驗證時已經啟用了ckeditor,所以在textarea中不需要再class="ckeditor")

 
        

 

 
        

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM