我使用的是BootstrapValidator,我有一些文本字段和一个带有两个选项的单选按钮,只有在选中了单选按钮选项2的情况下,我才需要验证文本字段,我如何才能获得它?
这是表单:
<form action="/it/Account/SignUp" class="form-horizontal" id="signup_form" method="post" role="form">
<label>Name</label>
<input type="text" name="name" class="form-control" id="name">
<label>Company</label>
<input type="text" name="company" class="form-control" id="company">
<input type="radio" name="usertype" value="0"><label>Private</label>
<input type="radio" name="usertype" value="1"><label>Company</label>
</form>这是BootstrapValidator的JavaScript:
$('#signup_form').bootstrapValidator({
message: 'This value is not valid',
live: 'disabled',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
name: {
validators: {
notEmpty: {
message: 'required'
},
}
},
company: {
validators: {
notEmpty: {
message: 'required'
},
}
},
}
}仅当'usertype‘的单选项值等于1时,我才需要验证"company“字段
发布于 2014-05-19 18:02:09
您应该查看callback验证选项
https://formvalidation.io/guide/validators/callback
您可以创建用于验证的自定义函数,返回布尔值true或false,然后根据是否选中该单选按钮对fieldValue进行检查
https://stackoverflow.com/questions/23726270
复制相似问题