我试图弄清楚如何使用Bootstrap Validator插件为文件上传设置minSize。
鉴于以下代码,我可以设置maxSize maxSize
,但不能设置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!'
}
}
}
}
});
});
有没有办法为minSize设置它?
答案 0 :(得分:2)
为nghuuphuoc/bootstrapvalidator
validators: {
file: {
extension: 'png',
type: 'image/png',
minSize: 1024*1024,
message: 'Please choose a png file with a size more than 1M.'
}
}
答案 1 :(得分:0)
在BootstrapValidator(v0.5.2-dev)的最新代码中, minSize 选项已实施。
所以你可以做到以下几点:
$(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!'
}
}
}
}
});
});
参考: