使用带引导插件的@jquery验证插件进行时间验证

时间:2013-06-19 07:19:11

标签: jquery

我在这里尝试验证数组中的时间。使用jquery验证插件并在错误时传递bootstrap的popover()函数。但它显示错误。

Cannot read property 'settings' of undefined 

这是我的代码。我想验证触发模糊事件的时间......

 $("input").blur(function() {

             var check = $(this).closest('tr').find('input');
                $.validator.addMethod(check, function(value, element) {

                    return this.optional(element) || /^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?$/i.test(value);
                }, "please enter the valid time");
                $(this).validate({
                    rules: {
                        'checkin[]': {
                            required: true
                        },
                        'checkout[]': {
                            rules: {
                                required: true
                            }
                        }
                    },
                    showErrors: function(errorMap, errorList) {


                        $.each(errorList, function(index, value) {
                            value.popover({
                                html: true,
                                trigger: 'blur',
                                content: function() {
                                    return 'Empty Textbox';

                                }
                            });
                        });



                        $.each(this.successList, function(index, value) {
                            $(value).popover('hide');


                            var form_data = $(this).closest('tr').find('input').serialize();





                            $.ajax(
                                    {
                                        url: "<?php echo site_url("HomeController/calculate_time_lap"); ?>",
                                        type: 'POST',
                                        data: form_data,
                                        success: function(result)
                                        {
                                            alert(result);
                                            // $('input').closest('tr').find('.TextBox3').val(result);
                                        }
                                    });
                            return false;
                        });
                    }
                });


            });

1 个答案:

答案 0 :(得分:0)

经过一段时间的努力终于找到了解决问题的方法......我们可以使用匹配函数以及jQuery验证插件的时间模式。

  $("input").blur(function() {
         if (!(this.value.match(/^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?$/i))) {
                    $(this).popover({
                        html: true,
                        trigger: 'blur',
                        content: function() {
                            return 'Invalid Time';

                        }
                    });

                    return false;
                }
                else {



                    var form_data = $(this).closest('tr').find('input').serialize();
                }




                $.ajax(
                        {
                            url: "<?php echo site_url("HomeController/calculate_time_lap"); ?>",
                            type: 'POST',
                            data: form_data,
                            success: function(result)
                            {
                               // alert(result);
                                $('input').closest('tr').find('.TextBox3').val(result);
                            }
                        });

                return false;
            });
相关问题