Skip to content

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

Open
@aruberutochan

Description

@aruberutochan

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 < array.length; j++) {
       var input_id = array[j];
       $(input_id).validate(function(valid, elem) {
          if (valid) {
              console.log('It looks valid');                                 
         } else {
              console.log('It is Invalid');
         }
    });  
});

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions