JQuery表单消息验证

时间:2014-04-26 16:18:02

标签: javascript jquery forms validation

我正在尝试验证为此表单工作,并且大多数情况下它正在运行。出现的问题仅在于我在“消息”输入字段中写入内容并单击“提交”时。提交表格,而不是阻止提交表格。

在Chrome控制台中提交后,我可以看到以下内容: “无法读取未定义的jquery.validate.min.js的属性'调用'”

var $taskForm = $("#task-form").validate({
        // Rules for form validation
        rules : {
            name : {
                required : true
            },
            'assign[]' : {
                required : true
            },
            checkin : {
                required : true
            },
            start : {
                required : true
            },
            completion : {
                required : true

            },
            message : {
                required : true,
                maxLength: 200,
                minlength : 10
            }
        },

        // Messages for form validation
        messages : {
            name : {
                required : 'Please enter a name for this task',
            },
            'assign[]' :{
                required : 'Please choose someone to assign this task to',
            },
            checkin : {
                required : 'Please choose a date',
            },
            completion : {
                required : 'Please choose a date',
            },
            message : {
                required : 'Please enter a description for the task'
            }
        },

        // Ajax form submition
        submitHandler : function(form) {
            $(form).ajaxSubmit({
                success : function() {
                    $("#task-form").addClass('submited');
                }
            });
        }


    });

1 个答案:

答案 0 :(得分:0)

您遇到语法错误,在所需消息的末尾不应该有逗号。

var $taskForm = $("#task-form").validate({
        // Rules for form validation
        rules : {
            name : {
                required : true
            },
            'assign[]' : {
                required : true
            },
            checkin : {
                required : true
            },
            start : {
                required : true
            },
            completion : {
                required : true

            },
            message : {
                required : true,
                maxLength: 200,
                minlength : 10
            }
        },

        // Messages for form validation
        messages : {
            name : {
                required : 'Please enter a name for this task'
            },
            'assign[]' :{
                required : 'Please choose someone to assign this task to'
            },
            checkin : {
                required : 'Please choose a date'
            },
            completion : {
                required : 'Please choose a date'
            },
            message : {
                required : 'Please enter a description for the task'
            }
        },

        // Ajax form submition
        submitHandler : function(form) {
            $(form).ajaxSubmit({
                success : function() {
                    $("#task-form").addClass('submited');
                }
            });
        }


    });