views:

58

answers:

2

I'm using the jQuery.validate() plugin for a form. However the form contains a fieldset (which is hidden, and used as a template for adding rows to the form) which I don't want to be validated. The fieldset will be named something like organisation_contacts_tmpl_33 with the invariant being the _tmpl_ part. I've tried:

$('#myform').validate({
  debug: true,
  ignore: '[id*="_tmpl_"] input'
  });

I've even renamed the fields inside the fieldset to start with tmpl_ and tried:

$('#myform').validate({
  debug: true,
  ignore: '[id^="tmpl_"]'
  });

(and multiple variations thereof) but to no avail . Any ideas?

+2  A: 

Why don't you just ignore hidden elements?

$('#myform').validate({
  debug: true,
  ignore: ':hidden'
});
BBonifield
Because they're not hidden! Only the containing fieldset is hidden. (Plus I think validate already ignores :hidden )
Dycey
"However the form contains a fieldset (which is hidden ...) which I don't want to be validated." - So is it hidden or no? And I don't believe validate ignores hidden elements by default - only disabled ones: http://docs.jquery.com/Plugins/Validation/validate .
BBonifield
@Dycey - `:hidden` is a visibility check, it doesn't by default ignore `:hidden` and the child elements are `:hidden` as well, so this looks like the approach you want.
Nick Craver
Yup, i was reading the source, and mentally (wrongly) seeing `.not(":submit, :reset, :image, [disabled]")` as `.not(":submit, :reset, :image, :hidden")` Apologies to Dr BBonifield!
Dycey
A: 

its just a jQuery selector that it expects see the documentation

this should work...

  $('#myform').validate({
    debug: true,
    ignore: '#fieldset_id input'
  });
mcgrailm
Yeees, except I'm generating #fieldset_id programmatically, and dynamically across lots of differen pages...
Dycey