views:

15

answers:

1

I need to validate a bunch of form fields within one element. I just need them all to be 'required', not necessarily input checked (email, phone number, etc). The problem is, I have the form dynamically showing and hiding inputs and select elements, and I need the validator to ignore hidden ones.

I have looked into this a fair amount - this, in theory, should work:

$('#theform').validate( {required: "input:visible,select:visible"}

It doesn't, the page just submits. There are several examples on this page, but I can't get any of them working. It's possible I'm implementing them wrongly.

Any help would be appreciated! Thanks for reading.

A: 

It's easier to use the ignore option here, like this:

$('#theform').validate({ ignore: ':hidden' });

I use this option to skip validation of dialogs that aren't presented for example, short and simple solution to the problem :)

Nick Craver
Hm, that just submits the form as well without any errors.
Gavin
@Gavin - Do you have a link to an example page? It sounds like you have a JavaScript error where it's not hooking up validation at all...if my code above didn't work the symptoms would be the hidden fields *still* validating, not the form skipping validation altogether, so something else must be happening here.
Nick Craver
Of course it was something simple.. I *completely* forgot to add parameters within the form, i.e. class names to reflect the requirements. Done and it works beautifully. ignore: ':hidden' was a much better way to go about it. Thanks!
Gavin