2014-12-05 44 views
5

我試圖用引導驗證引導驗證復位形式不工作

重置表單當我復位點擊,其消除輸入值,但是當我點擊提交即使輸入是空的,它仍然提交,當它應該顯示錯誤

這裏是JS

$('#shortener').bootstrapValidator({ 
     container: '#sstatus', 
     fields: { 
      url: { 
       validators: { 
        notEmpty: { 
         message: 'Enter a url!' 
        }, 
        uri: { 
         message: 'URL is not a valid url, include http://' 
        } 
       } 
      } 
     } 
    }).on('success.form.bv', function(e) { 
      // Prevent form submission 
      e.preventDefault(); 

      console.log('in'); 

      // Get the form instance 
      var $form = $(e.target); 

      // Get the BootstrapValidator instance 
      var bv = $form.data('bootstrapValidator'); 

      // Use Ajax to submit form data 
      $.post('ajax/new_url.php', $form.serialize(), function(result) { 

       console.log('works'+result.message); 

       $('#shortener').fadeOut('fast', function(){ 
        $form.bootstrapValidator('resetForm', true); 
       }); 

       $(document).on('click', '#shorten_again', function(e){ 
        e.preventDefault(); 
       }); 

      }, 'json'); 
    }); 

回答

-1

提交時,清除和重置您需要解決方法:

.on('init.field.bv', function(e, data) { 
     // data.bv  --> The BootstrapValidator instance 
     // data.field --> The field name 
     // data.element --> The field element 

     var $parent = data.element.parents('.form-group'), 
      $icon = $parent.find('.form-control-feedback[data-bv-icon-for="' + data.field + '"]'); 

     // From v0.5.3, you can retrieve the icon element by 
     // $icon = data.element.data('bv.icon'); 

     $icon.on('click.clearing', function() { 
      // Check if the field is valid or not via the icon class 
      if ($icon.hasClass('glyphicon-remove')) { 
       // Clear the field 
       data.bv.resetField(data.element); 
      } 
     }); 
    }) 

參考文獻:BootstrapValidator Clearing Field Example

1

$( '形式')bootstrapValidator( 'resetForm',TRUE);