I'm trying to prevent the jQuery Validation plugin from validating if a certain form option (phone only) is selected using $("#form_id").rules("remove", "required"); feature, but it's not working...
All I get is a javascript error when I select phone only: "TypeError: Result of expression 'F' [undefined] is not an object, and the form won't submit since it's still validating required fields.
//field validation
$('#location').change(function(){
location_val = $('#location').val();
if (location_val == "select") {
$('.hide').hide();
}
else if (location_val == "my_location") {
$('.hide').hide();
$('#f_address, #f_address2, #f_city, #f_state_zip, #f_phone').customFadeIn('fast');
$("#step2").rules("add", "required");
}
else if (location_val == "customers_location") {
$('.hide').hide();
$('#f_area, #f_phone, #f_city, #f_state_zip').customFadeIn('fast');
$("#step2").rules("add", "required");
}
else if (location_val == "both") {
$('.hide').hide();
$('#f_area, #f_address, #f_address2, #f_city, #f_state_zip, #f_phone').customFadeIn('fast');
$("#step2").rules("add", "required");
}
else if (location_val == "phone") {
$('.hide').hide();
$('#f_phone').customFadeIn('fast');
$("#step2").rules("remove", "required");
}
});
$("#step2").validate({
rules: {
city: {required: true},
state: {required: true},
zip: {required: true}
}
});
Insights appreciated.