Heim > php教程 > PHP开发 > Hauptteil

So schreiben Sie eine benutzerdefinierte BootstrapValidator-Validierungsmethode

高洛峰
Freigeben: 2016-12-03 10:13:09
Original
2055 Leute haben es durchsucht

Das Beispiel in diesem Artikel zeigt, wie Sie die benutzerdefinierte Verifizierungsmethode von BootstrapValidator als Referenz schreiben. Der spezifische Inhalt lautet wie folgt:

//表单验证
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();
  });
};
Nach dem Login kopieren


Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!