开发者

How to require fields if a certain radio button is checked with jQuery Validate?

开发者 https://www.devze.com 2023-03-11 05:23 出处:网络
I\'m using the code below with the jQuery Validate plug-in, h开发者_Python百科owever I\'m receiving the following error after clicking outside of one of the fields that should be required when \"Canad

I'm using the code below with the jQuery Validate plug-in, h开发者_Python百科owever I'm receiving the following error after clicking outside of one of the fields that should be required when "Canada" is checked. Any ideas?

province: {
    depends: function(element) {
        return $("input[name='country'][value='ca']").is(':checked')
    }
},

$.validator.methods[method] is undefined [Break On This Error] eval(function(p,a,c,k,e,d){e=function(...x5b|trigger|x21|x23'.split('|'),0,{}))


      $('#checkbox').click(function() {
            if ($(this).is(':checked')) {
                $('#element').rules('add', {
                    //rules
                });
            }

When you click on the checkbox to check the result, you can add the rules manually.


Not sure if this is your problem but your missing a semi-colon on this line

return $("input[name='country'][value='ca']").is(':checked');
0

精彩评论

暂无评论...
验证码 换一张
取 消