2014-12-01 36 views
2

是否可以手動將字段有效性設置爲無效bootstrap validator在自舉驗證器中手動設置有效性

我採用了棱角分明的JS在我的項目,要使用日期範圍驗證。

「最大最新的」屬性適用,除非我手動輸入的日期很好,這就是爲什麼我要重新驗證控制器領域和手動設置字段有效性。

HTML:

<div class="form-group inputGroupContainer" ng-controller="DatepickerCtrl"> 
     <label for="date">Date of Birth</label> 
     <p class="input-group"> 
      <input type="text" name="date1" placeholder="DD/MM/YYYY" class="form-control" ui-date="{dateFormat: 'dd/MM/yyyy'}" ui-date-format="dd/MM/yyyy" datepicker-popup="{{format}}" ng-model="user.Personal.BirthDate" max-date="currentDate" is-open="opened" close-text="Close" /> 
      <span class="input-group-btn"> 
       <button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button> 
      </span> 
     </p> 
    </div> 

angularjs控制器:

$scope.$watch('user.Personal.BirthDate', function (newValue, oldValue) { 
        if (newValue !== oldValue) { 
         if ($scope.user.Personal.BirthDate) 
          if ($scope.user.Personal.BirthDate.getTime() > new Date().getTime()) { 
//set validity for "date1" to invalid 
          } 
         $($('#editPersonalForm')).bootstrapValidator('revalidateField', 'date1'); 
        } 
       }); 

回答

3

這個插件最近改了名字formValidation和許可,但回到0.5.0這個工作對我來說。

力的輸入狀態爲INVALID

/** 
    * Update all validating results of field 
    * 
    * @param {String|jQuery} field The field name or field element 
    * @param {String} status The status. Can be 'NOT_VALIDATED', 'VALIDATING', 'INVALID' or 'VALID' 
    * @param {String} [validatorName] The validator name. If null, the method updates validity result for all validators 
    * @returns {BootstrapValidator} 
    */ 
$('#editPersonalForm').data('bootstrapValidator').updateStatus('date1', 'INVALID', null) 
+0

的情況下是非常有用的提示。 – 2017-08-15 11:43:23