I'm using the jquery validation plus the plugin from bassistance.de, the validation errors are being shown in a specific area of the screen and not besides the invalid form element this is achieved by specifying an empty errorPlacement function in the valid() method.
<div id="errbox" style="display: none"></div><br />
<form id="myform" method="post" action="#">
<fieldset>
<legend>1. Personal Details</legend>
<label for="firstName">First Name:</label>
<input type="text" id="firstName" name="firstName" size="30" required />
<br /><br />
<label for="lastName">Last Name:</label>
<input type="text" id="lastName" name="lastName" size="30" required />
</fieldset>
<br />
<input type="submit" value="Go" />
</form>
I would like the error messages to disappear/clear whenever the input has been corrected and it's valid against the validation rules. This happens if I take out the errorPlacement code and leave the message appearing besides the invalid element, but it doesn't if I show the error messages in the designated box.
This is my js code
$("#myform").validate({
messages: {
firstName: {required: "Please enter your First Name"},
lastName: {required: "Please enter your last name -
your maiden name if married"},
},
invalidHandler: function(form, validator) {
// This handler will show only one error at time - the first in this instance //
var errors = validator.numberOfInvalids();
if (errors) {
$("#errbox").html(validator.errorList[0].message);
$("#errbox").show();
validator.errorList[0].element.focus();
} else {
$("#errbox").hide();
}
},
errorPlacement: function(error, element) {
// Override error placement to not show error messages beside elements //
},
});
You can try the code here: http://jsfiddle.net/E7yPf/
I've tried to explicitly declare the onKeyUp and onFocusOut property and set them to true but it had no effect.
Is there anybody here who can help or point me in the right direction?
Thanks