admin管理员组文章数量:1294541
I'm using BootstrapValidator and I have some text fields and a radio button with 2 options, I need to validate a text field only if the radiobutton option 2 is selected, how can I obtain it?
This is the form:
<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="pany" class="form-control" id="pany">
<input type="radio" name="usertype" value="0"><label>Private</label>
<input type="radio" name="usertype" value="1"><label>Company</label>
</form>
This is the JavaScript for BootstrapValidator:
$('#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'
},
}
},
pany: {
validators: {
notEmpty: {
message: 'required'
},
}
},
}
}
I need only to validate the "pany" field only if the radio value of 'usertype' is equal to 1
I'm using BootstrapValidator and I have some text fields and a radio button with 2 options, I need to validate a text field only if the radiobutton option 2 is selected, how can I obtain it?
This is the form:
<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="pany" class="form-control" id="pany">
<input type="radio" name="usertype" value="0"><label>Private</label>
<input type="radio" name="usertype" value="1"><label>Company</label>
</form>
This is the JavaScript for BootstrapValidator:
$('#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'
},
}
},
pany: {
validators: {
notEmpty: {
message: 'required'
},
}
},
}
}
I need only to validate the "pany" field only if the radio value of 'usertype' is equal to 1
Share edited Dec 21, 2014 at 13:58 Zanon 30.8k21 gold badges118 silver badges126 bronze badges asked May 18, 2014 at 19:58 CaTouristCaTourist 7333 gold badges9 silver badges21 bronze badges 2- 1 Wele to Stack Overflow. Please provide an example of what you have tried so far, and the issues you encountered? You're more likely to receive a helpful response from the munity if you can demonstrate that you attempted to solve the problem before posting. – Alex Osborn Commented May 18, 2014 at 21:10
- i inserted a code sample – CaTourist Commented May 19, 2014 at 9:01
1 Answer
Reset to default 4You should look at the callback
validation option
https://formvalidation.io/guide/validators/callback
you can create a custom function for validation, return a boolean of true or false, you should then do your checks on the fieldValue depending on if the radio button is checked
本文标签: javascriptBootstrapValidator conditional validationStack Overflow
版权声明:本文标题:javascript - BootstrapValidator conditional validation - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741599812a2387630.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论