I have a very big form which I am splitting across four segments in a wizard like way. The wizard plugin (smart wizard) has the form segment currently in focus avtive while the remaining 3 segments are hidden in the dom.
I am using the jquery validate plugin to validate the form on the fly. The problem is validating that part of the form which is shown. Only when the user moves to the next step I want to run validation on that part of the form.
Is there a way to specify an array of elements to validate any the validation plugin is triggered ?
In the onLeaveStep option of the wizard plugin, I called the validate plugin. Weather or not the user clicks next or previous validation will be triggered.
var $myform = $("#registeration");
var validator = $myform.validate({
errorElement: "span",
rules: {
regtype: "required",
firstname: "required",
lastname: "required",
address1: "required",
city: "required",
country: "required",
phone1: "required",
email: {
required: true,
email: true
},
attendees: {
required: true,
digits: true
}
},
messages: {
regtype: "Select an option",
firstname: "Enter your first name",
lastname: "Enter your last name",
address1: "Enter your address",
city: "Enter your city",
country: "Enter your country",
phone1: "Enter your phone number",
email: "Enter your e-mail",
attendees: "Enter number of persons attending (including yourself)"
}
});
// Initialize Smart Wizard
$('#wizard').smartWizard({
transitionEffect:'slide',
hideButtonsOnDisabled:true,
transitionEffect: 'fade',
onLeaveStep: function(){
if(validator.form()){
//$myform.trigger('submit');
return true;
}else{
return false;
}
}
});