0

I wrote the following rule for my file field, as I wish to only accept Word Documents of PDF files.

paperupload:{required: true, accept: "application/msword, application/pdf"}

When I tested with uploaded a JPG file, the form submits without validating the other fields as well. Is there something wrong I've done here?

$("#papersubmitform").validate(
    {
        submitHandler: function(form) {

                        $(form).submit();

        },

        messages: {
            //CHECK Correspondence Authors' Information
            contactTitle: "Please specify Correspondence Author's Title",
            contactFirstName: "Please specify Correspondence Author's First Name",
            contactLastName: "Please specify Correspondence Author's Last Name",
            contactEmail: "Please specify Correspondence Author's Email Address",
            contactUniList: "Please specify Correspondence Author's University",
            //paperTitle:"Please specify Paper Title",
            paperAbstract:"Please specify Paper Abstract"

        },

        rules:{
            //Rules for Correspondence Author's Information
            contactTitle: {required: true},
            contactFirstName: { required:true},
            contactLastName: { required:true},  
            contactEmail: {required:true, email: true},
            contactUniList:{ required:function(){
                if(checkuninotinlist){ return false; }
                    else { return true; }
                }
            },

            contactUniversityName:{ required: function(){
                    if(checkuninotinlist){ return true; }
                    else { return false; }
                    }
            },

            contactUniCountry:{ required: function(){
                    if(checkuninotinlist){ return true; }
                    else { return false; }
                    }
            },


            contactOrganisation: { required:function(){ 
                    if(checkorganisation){ return true; }
                    else { return false; }
                    }
            },

            contactOrgCountry: { required:function(){ 
                    if(checkorganisation){ return true; }
                    else { return false; }
                    }
            },

            mailinglist:{required:true},
            researchmethod:{required:true},

            //PAPER INFORMATION
            paperTitle:{required:true},
            paperAbstract:{required:true},
            paperupload:{required: true, accept: "application/msword, application/pdf"}

    }
 });            

HTML HERE

<input type="file" name="paperupload" />
Sparky
  • 98,165
  • 25
  • 199
  • 285
kosherjellyfish
  • 361
  • 4
  • 16
  • @Norman, read the OP's code again. It's there; although it's not required. Just leave out the `submitHandler` and the plugin defaults to the same behavior as `$(form).submit()`. – Sparky Jan 04 '15 at 17:21

1 Answers1

1

You must include the additional-methods.js file in order to use the accept method.

Include it just after you include the jQuery Validate plugin.

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.validate.js"></script>
<script type="text/javascript" src="additional-methods.js"></script>
Sparky
  • 98,165
  • 25
  • 199
  • 285