2017-02-18 58 views
0

我有2個輸入和在點擊按鈕,我想檢查1個輸入驗證確實與否(這是爲了繞過所有的驗證只檢查1)formvalidation.io檢查的isValid的JavaScript

我可以重新驗證它,但我想要一些布爾反饋,如果它被驗證。 類似於'var isValidStep = fv.isValidContainer($ tab); '

謝謝。

<div class="col-xs-12 col-md-6 col-lg-4"> 
      <div class="form-group btn-group-bottom"> 
      <label for="fFname" class="child">First Name</label> 
      <input name="legalFirstName" class="form-control req" id="fFname" autocomplete="off" type="text" /> 
      </div> 
    </div> 

    <div class="col-xs-12 col-md-6 col-lg-4"> 
      <div class="form-group btn-group-bottom"> 
      <label for="fLname" class="child">Last Name</label> 
      <input name="legalLastName" class="form-control req" autocomplete="off" id="fLname" type="text" /> 
    </div> 

    <button type="button" value="Submit" class="btn btn-success easing-effect btn-padding btn-submit subbutton" name="submit" id="subbutton">Submit</button> 

    <script> 

    $('.rootwizard').formValidation({ 

      framework: 'bootstrap', 
      excluded: ':disabled', 
      live: 'enabled', 
      icon: { 
       valid: 'glyphicon glyphicon-ok', 
       invalid: 'glyphicon glyphicon-remove', 
       validating: 'glyphicon glyphicon-refresh' 
      }, 

      // Name Validation 
      locale: 'en', 
      fields: { 

       legalFirstName: { 
        live: 'enabled', 
        trigger: 'blur', 
        validators: { 
         stringLengthName: { 
          max: 30, 

         }, 
         notEmptyName: {}, 
         regexpName: { 
          regexpName: /^[a-zA-Z][a-z\sA-Z0-9.,$;]*$/, 

         } 
        } 
       }, 
       legalLastName: { 
        live: 'enabled', 
        trigger: 'blur', 
        validators: { 
         stringLengthName: { 
          max: 30, 

       }, 
       notEmptyName: {}, 
       regexpName: { 
          regexpName: /^[a-zA-Z][a-z\sA-Z0-9.,$;]*$/, 

         } 
        } 
       } 
     } 
    }); 

    $('.btn-submit').click(function() { 
     $('.rootwizard').formValidation('revalidateField', 'legalFirstName'); 
    }); 

回答

0

插件 '形式' 標籤到您的html和變型按鈕, '提交' 是這樣的:

<form class="rootwizard"> 
<div class="col-xs-12 col-md-6 col-lg-4"> 
     <div class="form-group btn-group-bottom"> 
     <label for="fFname" class="child">First Name</label> 
     <input name="legalFirstName" class="form-control req" id="fFname" autocomplete="off" type="text" /> 
     </div> 
</div> 

<div class="col-xs-12 col-md-6 col-lg-4"> 
     <div class="form-group btn-group-bottom"> 
     <label for="fLname" class="child">Last Name</label> 
     <input name="legalLastName" class="form-control req" autocomplete="off" id="fLname" type="text" /> 
</div> 

<button type="submit" value="Submit" class="btn btn-success easing-effect btn-padding btn-submit subbutton" name="submit" id="subbutton">Submit</button> 
</form>