我有一个非常大的表格,我以类似向导的方式将其分成四个部分。向导插件(智能向导)具有当前焦点 avtive 的表单段,而其余 3 个段隐藏在 dom 中。
我正在使用 jquery validate 插件来动态验证表单。问题是验证显示的表格部分。只有当用户移动到下一步时,我才想对表单的该部分运行验证。
有没有办法指定一个元素数组来验证任何验证插件被触发?
在向导插件的 onLeaveStep 选项中,我调用了 validate 插件。天气与否用户单击下一个或上一个验证将被触发。
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;
}
}
});