Hi, Tero.
In my application I have a dialog with form, that uses validator plugin to check user's input. If there are any error messages were displayed and user closed the dialog after that, previous messages continue to exist on the next pop-up while all form was cleaned. This is not correct.
I tried to find a method to reset validator's state, but with no success. Guess such method may be useful in some cases (e.g. to hide a error message on mouse click on it).
For fixing the issue I made a changes inside of validator function. It looks natural to clear all error messages when a form's 'reset' event is fired. Not sure if my code changes are fully correct, but it works for me. Here is the changed function (line 502):
$.fn.validator = function(conf) {
// check if empty
if (!this.length) { return this; }
// return existing instance
if (this.data("validator")) { return this; }
// configuration
conf = $.extend(true, {}, v.conf, conf);
// selector is a form
if (this.is("form")) {
var eff = effects[conf.effect];
if (!eff) { throw "Validator: cannot find effect \"" + conf.effect + "\""; }
return this.each(function() {
var form = $(this), inputs = form.find(":input"),
validator = new Validator(inputs, form, conf);
form.data("validator", validator);
form.bind("reset", function(e) {
// call the effect
eff[1].call(validator, inputs);
e.type = "onSuccess";
// trigger onSuccess
form.add(validator).trigger(e, [inputs]);
});
});
} else {
var validator = new Validator(this, this.eq(0).closest("form"), conf);
return this.data("validator", validator);
}
};
Thanks.