I have a form and each of its elements have their own custom rules working just fine, but I have a situation that the form can't be submmited without providing values for at least one of its elements.
I think this is a rule for the whole form and not for one specific element. I wrote a method that receives all the IDs of the form elements and checkes if they have values and attach it to a element of the form that is not passed as argument to this method, but I didn't think this is the best way to do it.
Any suggestions?
EDIT: As requested here's the method:
$.validator.addMethod("atLeastOne", function(value, element, params) {
if (!value) return false;
$.each(params, function(i, param) {
if (!$(param).val()) return false;
}
};
And in my form:
$("form").validate(
rules: {
field1: { atLeastOne: ["#field2","#field3","#field4","#field5","#field6"] }
});