jQuery-Form-Validator
jQuery-Form-Validator copied to clipboard
validate() Doesn't work inside an on('click' function
Hi. Thank you very much for your plugin, it is amazing. I am having an issue while I am trying to validate some fields programatically. In essential: I have a form that ends with a validate button, I'd like to program a web form which checks some fields passed with an array of Ids like array = ['#myId1', '#myId2'] i have this code:
$('#validate-button').on('click', function () {
for (var j = 0; j
However it is not sending anything to the console.
Curiously if i put the funciton .validate(... outside of the button click, it works, but not when it is inside.
Have I missed anything?
Thanks
Have you tried to debug every step?
$('#validate-button').on('click', function () {
console.log('button clicked');
for (var j = 0; j < array.length; j++) {
var input_id = array[j];
console.log($(input_id).length ? 'Found element to validate' : 'Did not find '+input_id);
$(input_id).validate(function(valid, elem) {
if (valid) {
console.log('It looks valid');
} else {
console.log('It is Invalid');
}
});
});
Yes, I put a console.log in every step and the one that doesn't fire is the one inside .validate function.
Yes, we have a bug here http://jsbin.com/wiginireji/edit?html,console,output
Fixed in tag 2.3.74
sorry, I forgot to say thanks :-)
Has this been added? I am using v.2.3.77 and validate() doesn't work for me. Similar code (running validate on click), put console.log everywhere and narrowed it down to the function not working. Any help?