jQuery-Form-Validator icon indicating copy to clipboard operation
jQuery-Form-Validator copied to clipboard

validate() Doesn't work inside an on('click' function

Open aruberutochan opened this issue 8 years ago • 6 comments
trafficstars

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

aruberutochan avatar Jul 13 '17 01:07 aruberutochan

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');
         }
    });  
});

victorjonsson avatar Jul 13 '17 07:07 victorjonsson

Yes, I put a console.log in every step and the one that doesn't fire is the one inside .validate function.

aruberutochan avatar Jul 13 '17 08:07 aruberutochan

Yes, we have a bug here http://jsbin.com/wiginireji/edit?html,console,output

victorjonsson avatar Jul 13 '17 08:07 victorjonsson

Fixed in tag 2.3.74

victorjonsson avatar Jul 14 '17 09:07 victorjonsson

sorry, I forgot to say thanks :-)

aruberutochan avatar Nov 29 '17 07:11 aruberutochan

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?

modelesque avatar Jan 04 '18 06:01 modelesque