2

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.

1 Answer 1

2

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 :)

Sign up to request clarification or add additional context in comments.

2 Comments

@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.
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!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.