File upload validation with jQuery Validate plugin

前端 未结 1 797
执笔经年
执笔经年 2021-01-14 11:09

I have a weird problem.I have a form with a file upload and few other textarea .each and every field is required.so basically when few fields are left blank,the validation w

相关标签:
1条回答
  • 2021-01-14 11:47

    Your code appears to be working just fine. Hidden fields are ignored by the Validate plugin. However, when you show the file upload field via radio button, it will validate and display the error message. See: http://jsfiddle.net/y5ghU/


    Your code:

    <input type="file" name="fupl" style="display:none;margin-top:10px" id="fup"/>
    

    Your file upload field is set to display:none; and the plugin will ignore all hidden fields by default.

    Use the ignore: [] option to disable this feature.

    $(document).ready(function () {
    
        $('#form').validate({
            ignore: [],
            rules: {
                fupl: {
                    required: true,
                    accept: 'docx|doc'
                }
            }
        });
    
    });
    

    DEMO: http://jsfiddle.net/ptV35/


    EDIT: Not really sure which way the OP wants to go, but the following demo hides any pending error message when the file upload field is re-hidden.

    $("#fup").next('label.error').hide();
    

    http://jsfiddle.net/y5ghU/4/

    0 讨论(0)
提交回复
热议问题