[英]Form validation styles not working
I've been experimenting with JQuery form validation, but haven't been able to get success/failure classes to be added once the validation has been complete. 我一直在尝试JQuery表单验证,但是一旦验证完成,就无法添加成功/失败类。
Here is my code: 这是我的代码:
https://jsfiddle.net/5WMff/ https://jsfiddle.net/5WMff/
<form method = "post" id = "signUpForm">
<div class="modal-body">
<div class="form-group">
<label for="firstName">First Name:</label>
<input type="text" class="form-control" name="firstName">
</div>
<div class="form-group">
<label for="surname">Surname:</label>
<input type="text" class="form-control" name="surname" >
</div>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" name="email">
</div>
<div class="form-group">
<label for="phoneNumber">Phone Number:</label>
<input type="phone" class="form-control" name="phoneNumber">
</div>
<div class="form-group">
<label for="postalCode">Home Postcode:</label>
<input type="text" class="form-control" name="postalCode">
</div>
<div class="checkbox">
<label><input type="checkbox" name = "acceptTCs">Accept Terms and Conditions</label>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn" data-dismiss="modal">Back</button>
<input type = "submit" name = "submit" class = "btn btn-success btn-large" value = "Submit" ></button>
</div>
</form>
JS: JS:
$(document).ready(function () {
$('#signUpForm').validate({
rules: {
firstName: {
minlength: 2,
required: true
},
surname: {
required: true,
email: true
},
email: {
minlength: 2,
required: true
},
phoneNumber: {
minlength: 7,
required: true
}
},
highlight: function (element) {
$(element).closest('.form-group').removeClass('success').addClass('error');
},
success: function (element) {
element.text('OK!').addClass('valid')
.closest('.form-group').removeClass('error').addClass('success');
}
});
});
The validation (OK vs. more info required) is working fine, it's just failing to add the success/failure class as well. 验证(可以,需要提供更多信息)工作正常,只是没有添加成功/失败类。 I know it's something obvious I've missed out, but have come to a bit of a dead end.
我知道我已经错过了很明显的事情,但是已经走到了死胡同。
The effect I'm looking for is like here: http://jsfiddle.net/5WMff/ 我要寻找的效果如下: http : //jsfiddle.net/5WMff/
Thanks. 谢谢。
$.validator.setDefaults({
submitHandler: function() {
alert("submitted!");
}
});
Use submitHandler . 使用SubmitHandler 。 Hope this will help you.
希望这会帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.