Dan G. Switzer, II wrote:
What I've done in the past is just add an onfocus event to remove the
classes:
// for any input field in the signup form, add a onfocus event
$("#userForm input").focus(
// everything in this function is executed
function (){
// $(this) performs the operation on the current jQuery
object
// this removes the error class from the field
$(this).removeClass("error");
// the label name is equal to the field "name" attribute
// for checkbox and radio elements and equal to the "id"
// attribute for all other fields
var sLabelName = ($(this)[0].type == "checkbox" ||
$(this)[0].type == "radio") ? $(this)[0].name : $(this)[0].id ;
// hide the error message for the current field
$("[EMAIL PROTECTED]" + $(this)[0].name +
"[EMAIL PROTECTED]").hide();
}
);
You probably want to use a more specific selector to just grab text fields,
radio, checkbox and textarea elements, but you get the idea.
It would be nice if this hook was automatically added by the validator
though...
This basically removes all hints of an invalid field on focus, right?
Allowing the use to start again, fixing the previous problems.
The plugin adds a focus-event-handler to all elements in the form
anyway, so the overhead of adding the cleanup would is minimal:
refresh: function() {
var validator = this;
this.elements = jQuery(this.currentForm).find(...).focus(function() {
validator.lastActive = this;
// hide error label and remove error class on focus if enabled
if ( validator.settings.focusCleanup ) {
$(this).removeClass(validator.settings.errorClass);
validator.errors().forId( validator.idOrName(this)
).hide();
}
});
},
Using the stuff already available in the plugin to get id/name and
select the appropiate error elements makes the code quite short and
effective.
Not so great when combined with focusInvalid.
--
Jörn Zaefferer
http://bassistance.de