Nisarg
Nisarg

Reputation: 3262

Input type ='file': validation not working

Here is my code

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://jquery.bassistance.de/validate/jquery.validate.js"></script>
<script src="http://jquery.bassistance.de/validate/additional-methods.js"></script>
<script>
   $(document).ready(function () {
   $('#uploled_file').validate({
       rules: {
                 extension: "xls|csv"
              }
       });
   });
</script>

and the form tag---

<form name="exportar_archivo_plano" id="exportar_archivo_plano" action="exportar_archivo_plano_action.php" method="post" enctype="multipart/form-data">
     <fieldset class="fieldsetspacer">
             <legend><span>Exportar Archivo Plano</span></legend>
                     <table width="40%" border="0">
                                    <tr></tr>
                                    <tr><div class="upload-error"></div></tr>
                                    <tr>
                                        <td><label for="fecharegistro">Seleccionar el Archivo</label></td>
                                        <td>
                                            <input type="file" name="uploled_file" id="uploled_file" style="width: 200px;" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td></td>
                                        <td>
                                            <input type="submit" name="uploled_submit" id="uploled_submit" value="Subir"/>
                                        </td>
                                    </tr>
                                </table>
                            </fieldset>
                        </form>

My ERROR :- form is simply submitted without validating of file.

Upvotes: 1

Views: 716

Answers (1)

Ram
Ram

Reputation: 144689

That's not an error. Validate the form element instead of the input:

$('#exportar_archivo_plano').validate({
    rules: {
       // Targeting form fields
       uploled_file: {
         // required: true,
         extension: "xls|csv"
       } 
    },
    submitHandler: function() {
       // Submit the form when validation passes
       this.submit();
    }
});

Upvotes: 2

Related Questions