如何在bootstrapvalidator中第二次验证相同的字段

时间:2017-03-01 08:12:04

标签: javascript jquery

在iam中,在onchange之后验证servicedescription并且工作正常但是每当我的文本更改为“OTHER”并且需要验证备注时只有StringLength

这是我的div

<div class="form-group" id="serviceDescription">
                                   <label class="control-label col-sm-3">Service Description:<span class="servicedescription hide" style="color:#FF0000;">*</span></label>
                                   <div class="col-sm-6">
                                       <textarea class="form-control" name="Remarks" id="Remarks" placeholder="Enter Service Description" rows="5"></textarea>
                                   </div>
                               </div>

这是我的onchange

.on('change', '[name="ServiceID"]', function () {
    var Serviceid = parseInt($("#ServiceID").val());
    var skillsSelect = document.getElementById("ServiceID");
    var selectedText = skillsSelect.options[skillsSelect.selectedIndex].text;

    if (selectedText == "OTHER") {

        $(".servicedescription").removeClass("hide");
        $('#AddServicesForm').bootstrapValidator('enableFieldValida‌​tors','Remarks');
        $('#AddServicesForm').bootstrapValidator('validateField', 'Remarks');

    }

    else{
        $('#AddServicesForm').bootstrapValidator('enableFieldValidators', 'Remarks', false)
        $(".servicedescription").addClass("hide");
    } 
})

这是我的bootstrapvalidator

Remarks: {
                        validators: {
                            notEmpty: {
                                message: 'Remarks is required and cannot be empty'
                            },
                            stringLength: {
                                min: 1,
                                max: 200,
                                message: 'Service Description must be 1 to 200 characters long'
                            },

                        }
                    },

0 个答案:

没有答案