Using depends with the jQuery Validation plugin

前端 未结 8 511
[愿得一人]
[愿得一人] 2021-01-12 11:52

I\'ve got a form with a bunch of textboxes that are disabled by default, then enabled by use of a checkbox next to each one.

When enabled, the values in these textbo

8条回答
  •  一向
    一向 (楼主)
    2021-01-12 12:43

    Shouldn't validate the field after disabling/enabling?

    jQuery('#ItemList :checkbox').click(function(event) {
            var textBox = jQuery(this).siblings(':text');
    
            if (!jQuery(this).attr("checked")) {
                    textBox.attr('disabled', 'disabled');
                    textBox.val('');
            } else {
                    textBox.removeAttr('disabled');
                    textBox[0].focus();
            }
            textBox.valid();    
    });
    

提交回复
热议问题