本文介绍了使用BootstrapValidator进行条件验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用BootstrapValidator插件来验证表单,但是我有以下问题.我有一个电话"字段和一个移动"字段,如果用户未输入任何一个,我想发出一条自定义消息(您需要告知一个电话号码),以及他是否告知任何一个(电话或移动电话)验证会得到满足.
I'm using BootstrapValidator plugin to validate a form, however i have following problem. I have a "Phone" field and a "Mobile" field if the user does not enter either of them, I wanted to launch a custom message (you need to inform one phone number), and if he inform any (phone or mobile) validation would be satisfied.
疑问是:是否可以在BootstrapValidator内部使用条件条件?
The doubt is: Is it possible to use conditional inside BootstrapValidator?
推荐答案
这似乎对许多从
$('form').validate({
rules: {
Phone: {
required: true
},
Mobile: {
required: true
}
},
highlight: function(element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function(element) {
$(element).closest('.form-group').removeClass('has-error');
},
errorElement: 'span',
errorClass: 'help-block',
errorPlacement: function(error, element) {
if(element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
});
和html:
<form>
<div class="form-group">
<label class="control-label" for="Phone">Phone:</label>
<div class="input-group">
<input class="form-control" name="Phone" type="text" />
</div>
</div>
<div class="form-group">
<label class="control-label" for="Mobile">Mobile:</label>
<div class="input-group">
<input class="form-control" name="Mobile" type="text" />
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
这篇关于使用BootstrapValidator进行条件验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!