值输入字段后如何重新验证ckeditor字段

时间:2019-10-31 06:38:14

标签: jquery bootstrapvalidator

我想使用bootstrapvalidator重新验证ckeditors字段。

Option1: {
    validators: {
        notEmpty: {
            message: 'The A is required'
        }
    }
},
Option2: {
    validators: {
        notEmpty: {
            message: 'The B is required'
        }
    }
},
Option3: {
    validators: {
        notEmpty: {
            message: 'The C is required'
        }
    }
},
Option4: {
    validators: {
        notEmpty: {
            message: 'The D is required'
        }
    }
},                    
QBQuestion: {
    validators: {
        notEmpty: {
            message: 'The QBQuestion is required and cannot be empty'
        }
    }
}

这是我的div代码:

<div class="row form-group">
    <div class="col-lg-12">
        <lable>Question</lable>
        <textarea name="QBQuestion" id="QBQuestion" rows="10" cols="80" class="form-control"></textarea>
    </div>
</div>

<div class="row form-group">
     <div class="col-lg-3">
         <lable>A</lable>
         <textarea name="Option1" id="Option1" rows="10" cols="80" class="form-control"></textarea>
     </div>
     <div class="col-lg-3">
         <lable>B</lable>
         <textarea name="Option2" id="Option2" rows="10" cols="80" class="form-control"></textarea>
     </div>
     <div class="col-lg-3">
         <lable>C</lable>
         <textarea name="Option3" id="Option3" rows="10" cols="80" class="form-control"></textarea>
     </div>
     <div class="col-lg-3">
         <lable>D</lable>
         <textarea name="Option4" id="Option4" rows="10" cols="80" class="form-control"></textarea>
     </div>
 </div>

在这里,我使用了bootstrapvalidator进行验证。输入一些文本后,不会重新验证字段。在这里,我有五个ckeditor字段。如果它们具有数据,我需要验证所有五个字段。

1 个答案:

答案 0 :(得分:0)

Ckeditor脚本正在隐藏文本区域,因此无法进行验证,请在Jquery中尝试此代码

 $(document).ready(function(){

        $("#form").validate(
        {
          ignore: [],
          debug: false,
            rules: { 

                Option1:{
                     required: function() 
                    {
                     CKEDITOR.instances.Option1.updateElement();
                    },

                     minlength:10
                }
            },
            messages:
                {

                Option1:{
                    required:"Please enter Text",
                    minlength:"Please enter 10 characters"


                }
            }
        });
    });

请注意,ignore: []对于激活验证很重要。