Advanced JQuery Validation: Avoiding Validations on Certain Conditions

前端 未结 1 1578
眼角桃花
眼角桃花 2020-12-18 11:38

I\'m making a form that I\'m using the amazing JQuery validation plugin for (http://docs.jquery.com/Plugins/Validation/).

This form allows people to make donations

相关标签:
1条回答
  • 2020-12-18 12:13

    The validation plugin allows for this, for a required attribute you aren't restricted to true/false, you can do this in your rules:

    CCNumber:{      
        required: "#<%=CreditCard.ClientID %>:visible",
        creditcard: "#<%=CreditCard.ClientID %>:visible"
    }
    

    Also, you can shorten your other syntax in the onload if you aren't restricted for some reason:

    $(function() {
        $("#<%=Cheque.ClientID %>").hide();
        $("#<%=CreditCard.ClientID %>").hide();
    });
    

    However, I'd suggest applying a "hidden" css style to them to avoid any possible flicker, then just using the $("#<%=Cheque.ClientID %>").show(); syntax to show them when whatever you do triggers it. Whatever method you go with, then :visible selector will work, it acts exactly like it sounds.

    0 讨论(0)
提交回复
热议问题