I am a newbie to jQuery and I aplogize if this question is very basic.
I am using bassistance’s Valiation plugin to validate a simple form. One of the text fields is mandatory – so I set required flag under rules and a corresponding message under messages. The problem I have is, once the validation kicks in, the error message I’ve set is displayed even if the field is blank (meaning, if the user deletes the contents of the field to start from scratch). Is there anyway to clear the error message or reset the validation if the field becomes empty? I tried to use the resetForm(), but looks like I can’t use it while it’s still validating. Here’s part of the code:
$(document).ready(function() {
var validator = $("#form1").validate({
rules: {
fname: {
required: true,
remote: 'http://localhost/check_name.php'
}
},
messages: {
fname: {
required: "Enter a valid jobname. eg: 99999_Disney",
remote: "Name already exists";
}
}
});
Thanks for your help!
I solved the problem. Not sure if it’s the most elegant way to do it, but it works. I had to clear the invalid state of the field somehow. I tried
resetForm()but that didn’t work. In the end I used something like this:and as needed added those rules back to the ID using: