I have huge form that I'd like to split in different steps, but I need to validate the fields in the current step before go to the next step.
E.g.: My form has 40 fields, and they are divided in 4 steps (10 fields each). In the HTML the 40 are in the same page, but with jQuery I only show the first 10 and a next button, the fourth page contains the "Submit" button. I need a way to invoke the validation of those ten fields before go to the next step.
Is there any way to accomplish this?
Regards.
If you are using buttons to move between each step, you can revise your page to have a separate form for each step. You then may limit validation to the form which is the parent of the submit button, and use the validation for the "step" to determine whether to enable/show the form for the next step. Here is some example code:
$(".stepButton").live("click", function() {
if (isValid(this)) {
// code to proceed to next step
}
});
function isValid(el) {
var $thisform = $(el).parent().parent();
$thisform.validate();
return $thisform.valid();
}