I have a form that is validated with the bassistance validate plugin. It all works very well (great plugin by the way) but I would like to disable the submit button until the form is valid.
According to the author Jörn Zaefferer (read comment here) I have to track the validity of all fields and then enable the button.
So I presume that I first have to find my all fields with a class name of 'required' and then check if they also have a class of 'valid', and then finally enable the button... but I am really struggling to do this (I have already spent 3.5 hours, it is driving me crazy!)
I tried to bind my input fields to listen for the 'valid' class using the timer technique that was proposed here, and came up with the following:
function doneTyping () {
var requiredFields = $('input').hasClass('required');
$(requiredFields).each(function(){
if ($(this).hasClass('valid')){
console.log('form is valid, enable button here');
} else {
console.log('form is not valid yet');
}
});
}
However my code doesn't work... Can someone please tell me if I am heading in the right direction?