I have a form where a user can toggle receiving funds either via check or via electronic transfer. When they choose either way in a list box, the respective part of the form hides. If they choose electronic transfer only bank info fields show, if they choose via check only address info shows and the bank fields are hidden.
Well, since they choose one way or another I want to, not validate for something that is hidden. (Client Side)
Is there a way to set xVal to only validate fields that are not visible?
I tried to override validate with the following but no dice...
$('#EditPayment').validate({
elementwhichishidden: {
开发者_如何学Gorequired: function(element) {
return ($(element).parent().parent().css('display') != 'none');
}
}
});
The best way to ignore fields that are hidden with xVal Validation, that I found, is to actually disable the hidden fields not in use. This way jQuery's validate()
will ignore them and not validate them.
validate()
is actually supposed to ignore anything that .is(':hidden')
but for some reason that didn't pan out for me. But disabling them worked like a charm.
精彩评论