I am working with the jQuery Validate plugin and I am trying to use the errorPlacement and success callbacks to add and remove the bootstrap class has-error.
Currently, the errorPlacement callback works but since the success callback returns the error label (which I'm not using) I'm not sure what to do. I need access to my input again in success but I don't know how to do it.
$('#msform').validate({
submitHandler: function (form) {
alert('valid form submitted');
return false; // for demo
},
errorPlacement: function(error, element) {
$(element).parent().addClass('has-error');
$(element).css('border-color', '#a94442');
},
success: function(label) {
label.removeClass('has-error').text('ok');
},
invalidHandler: function(event, validator) {
var errors = validator.numberOfInvalids();
}
});
Can anybody help? Thanks.
Edit:
I think I should be using highlight and unhighlight via combining custom error placement with success is not working jquery validate plugin.