jquery validation not working on an accordion

孤街醉人 提交于 2020-01-06 07:36:11

问题


sorry for the slightly general question here, but is there any reason why the jquery validate plugin would stop working on a form split across an accordion?

Just to explain, and I'm sorry I can't give a URL to an example. I've got an asp.net form which is split across an accordion. The mandatory fields are only on the first accordion panel. When this panel is open the validation works. If any of the other panels are open it won't validate.

For various strange reasons I'm calling the validation in an odd way. EG:

$('#submitBtn').click(function(){
   $('#form1').valid(); 
   if($('#form1').valid()){
      alert('valid');
   } else {
      alert('invalid');
      return false;
   }
});

Am I missing something obvious?

Thanks.


回答1:


By default, hidden input are ignored from validate plugin. Try this when initialising your jquery plugin which maybe could works for invisible input:

$("#form1").validate({
    ignore: "",
    ...
});



回答2:


The above answer did not work for me. The following did :

$.validator.setDefaults({ ignore: [] });

Make sure it is run before document is loaded.



来源:https://stackoverflow.com/questions/13878476/jquery-validation-not-working-on-an-accordion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!