2014-12-01 32 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