如何修复Uncaught TypeError:无法读取属性'设置'未定义的

时间:2016-04-03 09:47:03

标签: javascript jquery

我试图排除一个字段进行jquery验证,但问题是我遇到了这样可怕的错误。我的两个问题是如何为JQuery验证器排除一个字段以及如何解决Uncaught TypeError: Cannot read property 'settings' of undefined错误?

我正在使用这行代码:$('#datepicker').rules('remove', 'required');因为我想将其排除在验证之外。

这是我的HTML代码:

<tr>
    <td>Product Code: <br>
    <input disabled type="text" name="product_code_txt" id="product_code_addQty" required /></td>

    <td>Date Purchased: <br>
    <input type="date" name="date_txt" id="datepicker" class="date_addQty" required /></td>
</tr>

这是我的Jquery代码:

<script>
    $(function() {              
        $('.addQty_link').click(function(){
            var idnum = $(this).attr("value");
            //alert(idnum);

            addQuantity(idnum);

            function addQuantity(idnum){
                var addQty_dialog_form, formAddQty;
                var rules = { txtName: { required: true } };
                var messages = { txtName: { required: "Please enter name" } };

                $('#datepicker').rules('remove', 'required'); // not working and it has an error 

                $("#addQty-entry-form").validate({
                     rules: rules,
                     messages: messages
                });

                addQty_dialog_form=$('#dialog-addQty-form').dialog({
                    resizable: false,
                    hide: 'fade',
                    autoOpen: false,
                    width:440,
                    minheight:350,
                    modal: true,
                    open: function(event, ui) {
                      $(this).dialog('widget').position({ my: 'top', at: 'top+120', of: window });
                    },
                    buttons: {
                      "Update": function() {                                        
                          var reg=$("#addQty-entry-form").valid();
                          if(reg==false){
                            $('#addQty-entry-form .submit').click();
                          }
                          else if(reg==true){}
                          },
                          Cancel: function() {
                             addQty_dialog_form.dialog('close');
                          }
                    },
                    close: function() {
                        //formEdit[0].resetForm();
                        $("#addQty-entry-form").trigger("reset");
                        var validator = $( "#addQty-entry-form" ).validate();
                        validator.resetForm();
                    }
                }).css('overflow','hidden');

                addQty_dialog_form.dialog('open');

                formAddQty = addQty_dialog_form.find( "form" ).on( "submit", function( event ) {
                event.preventDefault();
                             // addUser();
                });
                return false;
            }                       
        });
    }); 
</script>

1 个答案:

答案 0 :(得分:0)

只需添加忽略

0