samedi 2 juillet 2016

JQuery Validation SubmitHandler for multple forms on same page


I have been using successfully the jQuery Validation script. But now I have the need to put two forms on one webpage.

I found the code to standardize the Validate rules and such, but I'm stumped on how to use what I've been using for inside the "submitHandler" part. I've been using it to produce a spinner gif (hide/show).

But now with having two forms on the same page, either one will activate the other spinner or they both activate or none activates when either submit button is clicked.

Any ideas on how to separate this out?

$(document).ready(function() {
  $('form').each(function() {
    $(this).validate({
        // edited out non-relevant code for this question //

        submitHandler: function(form) {

            $('#submitSpin').show();
            $('#submitButt').hide();
            form.submit();

        }, // END submitHandler

    }); // END this validate
  }); // END form each function
}); // END document ready function

So clearly I can't use the same ID for both forms' buttons; but if I make them different, I'm not sure how to write "IF this form is submitted, then show/hide these ID's, but if THIS OTHER form is submitted, then show/hide THESE other ID's" (so to speak).


Aucun commentaire:

Enregistrer un commentaire