0

成功后,验证器将 div 显示为黑色而不是绿色。如何让它以绿色显示。它不会在成功时将 has-success 类添加到 form-group div 中。

这是HTML

<form role="form" method="post" class="form-horizontal" id="anyForm"> 
<div class="form-group required">
    <label class="col-sm-4 col-xs-12 control-label">Meeting Days</label>
    <div class="col-sm-6 col-xs-12">
        <div class="row">
            <div class="col-sm-6 col-xs-12">
                <div class="checkbox">
                    <label><input type="checkbox" name="days[]" value="1">Monday</label>
                </div>
                <div class="checkbox">
                    <label><input type="checkbox" name="days[]" value="2">Tuesday</label>
                </div>
                <div class="checkbox">
                    <label><input type="checkbox" name="days[]" value="3">Wednesday</label>
                </div>
                <div class="checkbox">
                    <label><input type="checkbox" name="days[]" value="4">Thursday</label>
                </div>
            </div>
            <div class="col-sm-6 col-xs-12">
                <div class="checkbox">
                    <label><input type="checkbox" name="days[]" value="5">Friday</label>
                </div>
                <div class="checkbox">
                    <label><input type="checkbox" name="days[]" value="6">Saturday</label>
                </div>
                <div class="checkbox">
                    <label><input type="checkbox" name="days[]" value="7">Sunday</label>
                </div>
            </div>
        </div>
    </div>
</div>

验证

 $('#anyForm').formValidation({
     framework: 'bootstrap',
     icon: {
         valid: 'glyphicon glyphicon-ok',
         invalid: 'glyphicon glyphicon-remove',
         validating: 'glyphicon glyphicon-refresh'
     },
     fields: {
         "days[]" : {
             validators: {
                 notEmpty: {
                     message: 'Required field'
                 }
             }
         }
     }
 });

jsfiddle

4

1 回答 1

0

通过将 has-success 类添加到 onsuccess 事件获得了解决方法。

    $('#anyForm').
 formValidation({
     framework: 'bootstrap',
     icon: {
         valid: 'glyphicon glyphicon-ok',
         invalid: 'glyphicon glyphicon-remove',
         validating: 'glyphicon glyphicon-refresh'
     },
     fields: {
         "days[]" : {
             validators: {
                 notEmpty: {
                     message: 'Required field'
                 }
             }
         }
     }
 }).on('success.field.fv', function (e, data) {
     if (e.target.name == 'days[]') {
         var $parent = data.element.parents('.form-group');
         $parent.addClass('has-success');
     }
 });

更新了 JSFIDDLE

于 2015-10-13T08:07:36.547 回答