jQuery validate plugin require field if another field has a value and vice versa

Just for clarification this is what I ended up doing based on Erico's answer:

    firstInput: {
        required: function(element){
            return $("#secondInput").val().length > 0;
        }
    },
    secondInput: {
        required: function(element){
            return $("#firstInput").val().length > 0;
        }
    }

Each input is now dependent on the other and will only be required if the other has a value.


if you look at the "rules" section's example code in the documentation page, there is a depends field you can set.

something like the following (this is right off my head, not tested):

...
secondInput: {
    required: function(element){
            return $("#firstInput").val()!="";
        }
}
....