I have a date field that is required only if a text field has a value and vice versa.
Since it's conditional I can't just use the required attribute on the C# class, ie.
[Required(ErrorMessage = "*")]
So for the onChange
event of both fields I run this function:
function validateTermination()
{
if ($('#TerminationDate').val() == null && $('#TerminationReason').val() == null)
{
//remove validation
$('#TerminationDate').rules('remove');
$('#TerminationReason').rules('remove');
}
else
{
//add validation
$('#TerminationDate').rules('add', { required: true });
$('#TerminationReason').rules('add', { required: true });
}
}
Both of the add rule statements cause the error to throw. The error occurs in the jquery.validate.js file here:
var settings = $.data(element.form, "validator").settings;
I guess $.data(element.form, "validator")
is null for some reason, although I'm at a loss as to why.