JQuery validate plugin: check fields programmatically in specific sections of a page

I am trying to use the jQuery validation plugin (from here → http://bassistance.de/jquery-plugins/jquery-plugin-validation/) to programmatically validate fields in specific sections of a page based on a click on a button (and not in the form of the form submission to the end at the end of the section where it will validate the entire form) before moving to a new section. In fact, when you click a button in a specific section, the fields in this section should be checked. The first part of the page is checked just fine, but when I go to the second section, it just passes without checking. What is the right way to do this? Am I at least on the right track?
here is an example of what i'm talking about. If necessary, I can add more code.

// Step 1 section validation
var validateStep1 = $("#form1").validate({
    errorClass: "warning",
    onkeyup: false,
    onblur: false,
    onfocusout: true,
    rules: {
        "field1": {
            required: true,
        },
        "field2": {
            required: true,
            minlength: 1
        },
        "field3": {
            required: true,
        }
    }
});

// Step 2 section validation
var validateStep2 = $("#form1").validate({
    errorClass: "warning",
    onkeyup: false,
    onblur: false,
    onfocusout: true,
    rules: {
        "field4": {
            required: true,
        },
        "field5": {
            required: true,

        },
        "field6": {
            required: true,
        }
    }
});

// click events for buttons to proceed
$("#button1").click( function() {
    if (validateStep1.form()) {
        // proceed
    }
});
$("#button2").click( function() {
    if (validateStep2.form()) {
        // proceed
    }
});

Thanks in advance for your help!

+3
1

, - 'validate' .

, "" . "" "".

: http://rocketsquared.com/wiki/Plugins/Validation/validate#toptions ( )

$(".selector").validate({
    rules: {
        contact: {
            required: true,
            email: {
                depends: function(element) {
                    return $("#contactform_email:checked")
                }
            }
        }
    }
});

, , .

+4

All Articles