views:

32

answers:

1

As above, how can I remove all of the required rules from a form using jQuery Validate?

This is what I have at present:

var settings = $('form').validate().settings;

//alert(settings.rules.toSource());
for (var i in settings.rules){
    alert(i);
    delete settings.rules.i; 
    // ^ not sure about how to do this properly,
    // and how to just delete the 'required' rule and keep the rest intact
}

The function native to jQuery Validate returns an undefined error:

$("input, select, textarea").rules('remove','required');
+2  A: 

As can sometimes be the case, I appear to have stumbled on the answer just after resorting to posting on here.

for (var i in settings.rules){
   delete settings.rules[i].required;
}

Works.

bcmcfc