Jquery.Validate文件上传绕过其他字段的验证

时间:2015-11-09 15:30:10

标签: javascript jquery validation

当文件上传附加了文件时,Jquery.Validate似乎绕过了对其他字段的验证。我也添加了additional-methods.js扩展名。任何帮助将不胜感激。这是代码:

 $("#submitnoclaimsproof-form").validate({
        errorClass: "error",
        rules: {
            name: { required: true, maxlength: 255 },
            policynumber: { required: true, maxlength: 255 },
            postcode: { required: true, maxlength: 255 },
            reg: { required: true, maxlength: 255 },
            previousinsurer: { required: true, maxlength: 255 },
            previouspolicynumber: { required: true, maxlength: 255 },
            subscribe: { required: true },
            file: { required: true, uploadFile: true }
        },
        messages: {
            name: { required: "Name required" },
            policynumber: { required: "Policy Number is required" },
            postcode: { required: "Postcode is required" },
            reg: { required: "Vehicle Registration required" },
            previousinsurer: { required: "Previous Insurer required" },
            previouspolicynumber: { required: "Previous Policynumber required" },
            file: { required: "Proof of no claims required" },
            subscribe: { required: "Please confirm" }
        },
    });

表格:

    <form id="submitnoclaimsproof-form" class="form-horizontal" role="form" action="./SubmityourNoClaimsBonusProofScript" method="post" enctype="multipart/form-data">
<div class="form-response">            
            <div class="form-group">
                <div class="col-sm-4">
                    <label for="name" class="control-label">Name:</label>
                </div>
                <div class="col-sm-6">
                    <input type="text" class="form-control" id="name" name="name" placeholder="Your Name...">
                </div>
                <div class="col-sm-6 col-sm-offset-4 error-message">
                    <label for="name" generated="false" class="error"></label>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-4">
                    <label for="policynumber" class="control-label">Policy Number:</label>
                </div>
                <div class="col-sm-6">
                    <input type="text" class="form-control" id="policynumber" name="policynumber" placeholder="Policy Number...">
                </div>
                <div class="col-sm-6 col-sm-offset-4 error-message">
                    <label for="policynumber" generated="false" class="error"></label>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-4">
                    <label for="postcode" class="control-label">Home Postcode:</label>
                </div>
                <div class="col-sm-6">
                    <input type="text" class="form-control" id="postcode" name="postcode" placeholder="Postcode...">
                </div>
                <div class="col-sm-6 col-sm-offset-4 error-message">
                    <label for="postcode" generated="false" class="error"></label>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-4">
                    <label for="reg" class="control-label">Vehicle Registration:</label>
                </div>
                <div class="col-sm-6">
                    <input type="text" class="form-control" id="reg" name="reg" placeholder="Vehicle Registration...">
                </div>
                <div class="col-sm-6 col-sm-offset-4 error-message">
                    <label for="reg" generated="false" class="error"></label>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-4">
                    <label for="file" class="control-label">Upload your NCB Proof: </label>
                </div>
                <div class="col-sm-6">
                    <input type="file" id="file" name="file" class="" placeholder="Your NCB Proof...">
                </div>
                <div class="col-sm-6 col-sm-offset-4 error-message">
                    <label for="file" generated="false" class="error"></label>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-4">
                    <label for="previousinsurer" class="control-label">Previous Insurer: </label>
                </div>
                <div class="col-sm-6">
                    <input type="text" class="form-control" id="previousinsurer" name="previousinsurer" placeholder="Previous Insurer...">
                </div>
                <div class="col-sm-6 col-sm-offset-4 error-message">
                    <label for="previousinsurer" generated="false" class="error"></label>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-4">
                    <label for="previouspolicynumber" class="control-label">Previous policy number:</label>
                </div>
                <div class="col-sm-6">
                    <input type="text" class="form-control" id="previouspolicynumber" name="previouspolicynumber" placeholder="Previous policy number...">
                </div>
                <div class="col-sm-6 col-sm-offset-4 error-message">
                    <label for="previouspolicynumber" generated="false" class="error"></label>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-12 submit">
                    <button type="submit" class="btn btn-secondary submit-button">Submit Request<i class="fa fa-chevron-right"></i></button>
                </div>
            </div>
        </div>
    </form>     

1 个答案:

答案 0 :(得分:0)

没有验证方法名称&#34; uploadFile &#34; (除非您已经自己编写了它),因此当文件控件附加文件时会发生异常。