问题
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