简体   繁体   English

jQuery表单消息验证

[英]JQuery Form Message Validation

I am trying to validation working for this form and for the most part it is working. 我正在尝试验证此表单是否有效,并且在大多数情况下都可以正常工作。 The problem arises is solely when I write something in the "Message" input field and click submit. 仅当我在“消息”(Message)输入字段中输入内容并单击提交时,才会出现问题。 Instead of preventing the form from being submitted, the form is submitted. 而不是阻止提交表单,而是提交表单。

Upon submission in the Chrome console I can see the following: "Cannot read property 'call' of undefined jquery.validate.min.js" 在Chrome控制台中提交后,我会看到以下内容:“无法读取未定义的jquery.validate.min.js的属性'call'

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');
                }
            });
        }


    });

You have syntax errors, you should not have a comma at the end of your required messages. 您有语法错误,在所需消息的末尾不应使用逗号。

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');
                }
            });
        }


    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM