本文實例為大家分享了bootstrapValidator自定驗證方法寫法,供大家參考,具體內容如下
//表單驗證
issueInvoiceForm.validation = function(){
$('#issueInvoiceForm').on('init.field.bv', function(e, data) {
var $icon = data.element.data('bv.icon'),
options = data.bv.getOptions(), // Entire options
validators = data.bv.getOptions(data.field).validators; // The field validators
if (validators.notEmpty && options.feedbackIcons && options.feedbackIcons.required) {
$icon.addClass(options.feedbackIcons.required).show();
}
}).bootstrapValidator({
container:'popover',
feedbackIcons: {
required: 'glyphicon glyphicon-asterisk requiredStar',
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
invoiceDate:{validators: {notEmpty: {message: '開票日期不能為空'}}},//開票日期
code:{validators: {notEmpty: {message: '發票編碼不能為空'}}},
amount:{
validators:{
notEmpty: {message: '發票金額不能為空'},
numeric: {message: '發票金額只能輸入數字'},
callback: {
message: '開票金額小於選中金額',
callback: function(value, validator) {
return false;
}
}
}
},
taxRate:{
validators:{
notEmpty: {message: '稅率不能為空'},
numeric: {message: '稅率只能輸入數字'}
}
},
taxAmount:{
validators:{
notEmpty: {message: '稅額不能為空'},
numeric: {message: '稅額只能輸入數字'}
}
},
},group:'.validateDiv'
}).on('success.form.bv', issueInvoiceForm.issueInvoiceFormBtn).on('error.form.bv',function(){
$("#issueInvoiceFormBtn").removeAttr("disabled");//將保存按鈕去除disabled
$(".has-error:visible:first").find(":input").focus();
});
};
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持。