How can I set up my validator so it will check all fields on the form whenever changes the value of any input on this form. I've tried
$("#form-user-edit").validate({
keypress : true
});
but it's not working.
I've made a jsFiddle http://jsfiddle.net/NickBunich/pDrTF/1/
The problem is that when u type something in first input - other inputs become enabled, but if u then type something in second input, then erase it and then erase text in first input - error message and highlight will stay.
The following answer demonstrates the proper usage of the built-in callback event functions of the plugin. The creation of external callback functions is superfluous and unnecessary.
Your code...
$("#form-user-edit").validate({
keypress : true
});
You cannot simply "make-up" or "invent" .validate()
options. keypress:
does not exist. See this page for the only available options.
How can I set up my validator so it will check all fields on the form whenever changes the value of any input on this form.
There is already an option called onkeyup
and it's turned on by default. (This checks only the active input on every key-up event.)
You could modify onkeyup
to suit your needs. This will check the entire form on every key-up event.
$(document).ready(function() {
$("#form-user-edit").validate({
// other rules and options,
onkeyup: function (element, event) {
if (event.which === 9 && this.elementValue(element) === '') {
return;
} else if (element.name in this.submitted || element === this.lastActive) {
if($("#form-user-edit").valid()) {
$("#form-user-edit .error").removeClass('error');
};
}
}
});
});
Working Demo: http://jsfiddle.net/CMT5r/
Working demo contains the OP's code modified to function as requested.