我正在开发一个CodeIgniter应用程序,其中我有一个包含多个块的表单,这些块具有共同或不同的字段。 我有一个选择框,在选择一个选项时,我将启用/禁用块(div)。一次可以看到一个块。我正在使用jquery验证插件来验证表单。由于隐藏块的必填字段,我在尝试提交表单时遇到问题。任何人都可以告诉我如何解决这个问题
$("#form").validate({
ignore: [],
rules:{
company:{
required:true
},
location_name:{
required:true
},
address:{
required:true
},
city:{
required:true
},
pincode:{
required:true
},
sender_name:{
required:true,
minlength:3,
maxlength:50,
firstletter:true
},
email:{
required:true,
email:true
},
mobile_num:{
required:true,
minlength:10,
mobvalid:true
},
phone_num:{
minlength:10
},
state:{
required:true
},
type_of_sample:{
required:true
},
manufacturer_id:{
required:true
}
},
messages:{
company:{
required:"Please select company name"
},
location_name:{
required:"Please select the location"
},
address:{
required:"Please enter the address"
},
city:{
required:"Please enter the city"
},
pincode:{
required:"Please enter the pincode"
},
sender_name:{
required:"Please enter firstname",
minlength:"Please enter atleast 3 characters",
maxlength:"Maximum 50 characters allowed"
},
email: {
required:"Please enter the email address",
},
mobile_num:{
required:"Please enter mobile number",
},
state:{
required:"Please select the state"
},
type_of_sample:{
required:"Please select the type of sample"
},
manufacturer_id:{
required:"Please select any manufacturer"
}
},
submitHandler: function(form) {
form.submit();
}
});
这里manufacturer_id位于隐藏块中,阻止我提交表单。请帮帮我。
答案 0 :(得分:0)
您可以尝试这样做,有一个参考链接:
$.validator.setDefaults({
ignore: ":hidden"
});
参考文献:http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js
答案 1 :(得分:0)
从函数中删除ignore属性
$("#form").validate({
ignore: [], //remove this attribute
});
所以你的代码看起来像
$("#form").validate({
rules:{
company:{
required:true
},
location_name:{
required:true
},
address:{
required:true
},
city:{
required:true
},
pincode:{
required:true
},
sender_name:{
required:true,
minlength:3,
maxlength:50,
firstletter:true
},
email:{
required:true,
email:true
},
mobile_num:{
required:true,
minlength:10,
mobvalid:true
},
phone_num:{
minlength:10
},
state:{
required:true
},
type_of_sample:{
required:true
},
manufacturer_id:{
required:true
}
},
messages:{
company:{
required:"Please select company name"
},
location_name:{
required:"Please select the location"
},
address:{
required:"Please enter the address"
},
city:{
required:"Please enter the city"
},
pincode:{
required:"Please enter the pincode"
},
sender_name:{
required:"Please enter firstname",
minlength:"Please enter atleast 3 characters",
maxlength:"Maximum 50 characters allowed"
},
email: {
required:"Please enter the email address",
},
mobile_num:{
required:"Please enter mobile number",
},
state:{
required:"Please select the state"
},
type_of_sample:{
required:"Please select the type of sample"
},
manufacturer_id:{
required:"Please select any manufacturer"
}
},
submitHandler: function(form) {
form.submit();
}
});