我希望在成功时隐藏 span.help-block,因为它正在被添加(没有内容)并将其余内容向下推
我尝试添加成功:函数 $('.help-block').hide() 但这只会在从下一个表单输入继续后隐藏跨度。
如果我将它添加到成功函数之外,它将起作用,但我需要以某种方式捕捉验证是否成功,然后隐藏帮助块
if (jQuery().validate) {
var removeSuccessClass = function(e) {
$(e).closest('.form-group').removeClass('has-success');
}
$('#validation-form').validate({
errorElement: 'span', //default input error message container
errorClass: 'help-block', // default input error message class
errorPlacement: function(error, element) {
if(element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
},
focusInvalid: false, // do not focus the last invalid input
ignore: "",
invalidHandler: function (event, validator) { //display error alert on form submit
},
highlight: function (element) { // hightlight error inputs
$(element).closest('.form-group').removeClass('has-success').addClass('has-error'); // set error class to the control group
},
unhighlight: function (element) { // revert the change dony by hightlight
$(element).closest('.form-group').removeClass('has-error'); // set error class to the control group
setTimeout(function(){removeSuccessClass(element);}, 3000);
},
success: function (label) {
label.closest('.form-group').removeClass('has-error').addClass('has-success'); // set success class to the control group
}
// if i put $('.help-block').hide(); here it works but I need to
// find if the validatoin was a success
if(VALIDATE IS SUCCESS){
$('.help-block').hide();
}
});
}