How to set minSize in Bootstrap Validator

心不动则不痛 提交于 2020-01-02 14:03:22

问题


I'm trying to figure out how to set the minSize for a file upload using Bootstrap Validator plugin.

Given the following code, I can set the maxSize maxSize, but not minSize

$(document).ready(function () {
        $('#test').bootstrapValidator({
            live: 'enabled',
            fields: {
                fileupload: {
                    validators: {
                        file: {
                            extension: 'png',
                            type: 'image/png',
                            maxSize: 1024 * 1024,
                            message: 'The selected file is not valid, or the size is not large enough!'
                        }
                    }
                }
            }
        });
    });

Is there a way to set it for minSize?


回答1:


as nghuuphuoc/bootstrapvalidator


validators: {
    file: {
        extension: 'png',
        type: 'image/png',
        minSize: 1024*1024,
        message: 'Please choose a png file with a size more than 1M.'
    }
}



回答2:


In the latest code of BootstrapValidator (v0.5.2-dev), the minSize option was implemented.

So you can do the following :

$(document).ready(function () {
    $('#test').bootstrapValidator({
        live: 'enabled',
        fields: {
            fileupload: {
                validators: {
                    file: {
                        extension: 'png',
                        type: 'image/png',
                        minSize: 100*1024, // for example 100 KO 
                        maxSize: 1024 * 1024,
                        message: 'The selected file is not valid, or the size is not large enough!'
                    }
                }
            }
        }
    });
});

Refrences :

  • The latest code of File validator.
  • Pull request #803.
  • File validator example : demo/file.html.


来源:https://stackoverflow.com/questions/25649867/how-to-set-minsize-in-bootstrap-validator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!