12

So basically I have a simple POST form that is being validated using Validate library from jquery, and it all works fine, but then I used the tabs function from bootstrap and many other libraries to separate the form into two different tabs. The problem now is that validation happens only to the open (visible) tab, regardless the condition of the other input fields in hidden tabs. Any possible suggestions?

Florent
  • 12,310
  • 10
  • 49
  • 58
Khaled
  • 8,255
  • 11
  • 35
  • 56

2 Answers2

28

I think your trouble might be that jquery by default will only validate visible fields. So what you need to do is tell jquery to not ignore your hidden fields (other tabs). This can be done as follows:

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

By default ignore: ":hidden".
See this answer, and this documentation (Options -> Ignore).

Community
  • 1
  • 1
Miika L.
  • 3,333
  • 1
  • 24
  • 35
3

Please see the accepted answer above, it is really helpful.
Just in case of using unobtrusive validation, then the accepted answer will not work, and here is the solution.

$("#form1").data("validator").settings.ignore = "";

see this

Community
  • 1
  • 1
Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
  • 1
    Thanks, you saved my day. I've been seeing the solution from accepted answer everywhere and was wondering why it's not working for me. cheers! – Pirate Apr 21 '21 at 13:57