bootstrapValidator表单验证文件上传-图片部分
写在最前
bootstrapValidator表单验证配合fileinput使用时的图片验证问题。
代码描述
$('#thisForm').bootstrapValidator({
message: '请正确输入',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
trigger: 'change',
fields: {
TABLOID_TITLE: {
validators: {
notEmpty: {
message: '标题不能为空'
},
stringLength: {
min: 1,
max: 50,
message: '标题长度必须在1到50之间'
}
}
},
file: {
validators: {
notEmpty: {
message: '上传图片不能为空'
},
file: {
extension: 'png,jpg,jpeg',
type: 'image/png,image/jpg,image/jpeg',
message: '请重新选择图片'
}
}
}
}
}).on('success.form.bv', function (e) { //点击提交验证通过之后
e.preventDefault();
$('[type="submit"]').removeAttr("disabled");
//TODO
}).on('error.form.bv', function (e) { //点击提交验证失败之后
$('[type="submit"]').removeAttr("disabled");
});
文字描述
这里记录一下bootstrapValidator在验证上传图片文件时的些许小配置;坑在于type: ‘image/png,image/jpg,image/jpeg’,中间不能有空格,bootstrapValidator在源码中直接使用’,’进行分割到数据然后匹配。
写在最后
从坑中来,到坑中去…
谢谢大家