gpt4 book ai didi

jquery - bootstrap formValidation 复选框组未添加 has-success

转载 作者:行者123 更新时间:2023-11-28 07:07:03 25 4
gpt4 key购买 nike

成功时,验证器以黑色而不是绿色显示 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

最佳答案

通过向 onsuccess 事件添加 has-success 类获得了解决方案。

    $('#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');
}
});

Updated JSFIDDLE

关于jquery - bootstrap formValidation 复选框组未添加 has-success,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32883127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com