下面是我的代码,一旦bValidator仅在提交按钮点击时返回true,我怎么能调用SubmitMedicalSignup()函数?
<form method="post" data-bvalidator-validate data-bvalidator-option-validate-till-invalid="true">
<label class="label required"> First Name <font>:</font> </label>
<input type="text" name="contact_person_first_name" ng-model="MedicalData.contact_person_first_name" class="form-control" data-bvalidator="alpha,minlen[50],required" data-bvalidator-msg="First Name Required.">
<button type="submit" name="" id="" ng-click="SubmitMedicalSignup()" value="Register as a physician" class="btn-blue"> Submit
</form>
<!-- validation -->
<script type="text/javascript" src="<?php echo FRONTEND_THEME_URL ?>js/vendor/jquery.bvalidator.js"></script>
<script type="text/javascript" src="<?php echo FRONTEND_THEME_URL ?>js/themes/presenters/default.min.js"></script>
<script type="text/javascript" src="<?php echo FRONTEND_THEME_URL ?>js/themes/gray/gray.js"></script>
<link href="<?php echo FRONTEND_THEME_URL ?>js/themes/gray/gray.css" rel="stylesheet" />
<script type="text/javascript">
$(document).ready(function () {
$('form').bValidator();
});
</script>
答案 0 :(得分:1)
您可以使用ng-click="bValidator && SubmitMedicalSignup()"
等表达式。它应该做的伎俩,但它不是实现这一目标最干净的方法。你可以做的是在你的相关控制器中调用一个函数来检查bValidator是否为true然后触发你的函数。
答案 1 :(得分:0)
您可以将validateOnSubmit
选项设置为false
,并在表单提交时使用javascript调用验证,如果没有验证错误,请致电SubmitMedicalSignup()
:
<form method="post" data-bvalidator-validate data-bvalidator-option-validate-till-invalid="true" data-bvalidator-option-validate-on-submit="false">
....
....
<script type="text/javascript">
$(document).ready(function () {
$('form').on('submit', function (e) {
e.preventDefault(); // stop submit event
if($('form').data('bValidator').validate()){
SubmitMedicalSignup();
$('form').submit(); // submit the form
}
});
});
</script>
答案 2 :(得分:0)
flag = 0;
jQuery("form").on("submit", function (e) {
if(flag == 0){
e.preventDefault();
if(jQuery('form').data('bValidator').validate()) {
// Do your processing
flag = 1;
jQuery("form").submit();
}
} else {
flag = 0;
}
});
答案 3 :(得分:0)
在提交时调用操作方法,如ng-submit="function_name()"
<form method="post" data-bvalidator-validate data-bvalidator-option-validate-till-invalid="true" ng-submit="function_name()">
然后它将运行第一个bvalidator函数,然后它将调用提交函数。