Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用ui引导版本1.3.3时,无法在angular ui引导日期选择器中添加最小日期和最大日期验证_Javascript_Angularjs_Validation_Date - Fatal编程技术网

Javascript 使用ui引导版本1.3.3时,无法在angular ui引导日期选择器中添加最小日期和最大日期验证

Javascript 使用ui引导版本1.3.3时,无法在angular ui引导日期选择器中添加最小日期和最大日期验证,javascript,angularjs,validation,date,Javascript,Angularjs,Validation,Date,我正在尝试在我的日期选择器中添加验证,以便用户不能选择当前日期前30天的任何日期,也不能选择未来30天的任何日期。我使用以下代码作为日期选择器- <div class="form-group" ng-class="{ 'has-error' : memberForm.dateOfBirth.$invalid && (memberForm.dateOfBirth.$touched || memberForm.$submitted) }"> <label for

我正在尝试在我的日期选择器中添加验证,以便用户不能选择当前日期前30天的任何日期,也不能选择未来30天的任何日期。我使用以下代码作为日期选择器-

<div class="form-group" ng-class="{ 'has-error' : memberForm.dateOfBirth.$invalid && (memberForm.dateOfBirth.$touched || memberForm.$submitted) }">
  <label for="Date of Birth" class="" ng-hide="memberForm.dateOfBirth.$invalid && (memberForm.dateOfBirth.$touched || memberForm.$submitted)">Date of Birth(dd/mm/yyyy)*</label>
  <label class="error_message_text" ng-show="memberForm.dateOfBirth.$invalid && (memberForm.dateOfBirth.$touched || memberForm.$submitted)"> Date of birth is required </label>
  <p class="input-group" style="width:270px;">
    <input type="text" class="form-control" name="dateOfBirth" uib-datepicker-popup="dd/MM/yyyy" ng-model="dt" is-open="popup1.opened" datepicker-options="dateOptions" ng-required="true" close-text="Close" alt-input-formats="altInputFormats" />
    <span class="input-group-btn">
      <button type="button" class="btn btn-default" ng-click="open1()"><i class="glyphicon glyphicon-calendar"></i></button>
    </span>
  </p>
</div>

出生日期(年月日)*
出生日期是必需的

我正在使用下面的脚本-

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.js"></script>  
<script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-1.3.3.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"> 

我在这里创造了一个劫掠者-


有谁能告诉我如何在代码中实现这种验证吗?

您可以使用它进行验证

var today = new Date()
var priorDate = new Date().setDate(today.getDate()-30)
问题在于:

$scope.minDate = date.setDate((new Date()).getDate() - 30);
调用date.setDate(..)时,它不会返回date对象,因此请执行以下操作

$scope.toggleMin = function() {
    var date = new Date();
    date.setDate((new Date()).getDate() - 30);
    $scope.minDate = date;
  };
  $scope.toggleMin();


var date1 = new Date();
date1.setDate((new Date()).getDate() + 30);
$scope.dateOptions.maxDate = date1;
小修正-(在指定最小日期和最大日期时添加了.dateOptions)

回答普朗克-

您可以添加
min date=“minDate”
max date=“maxDate”
刚设置的最小日期为当前日期,最大日期为.addDays(30)的可能副本。@Matheno@Abhay我尝试过但不起作用,我已经更新了我的plunker-@Matheno你能纠正我的plunker吗?我尝试过这个,但不起作用,我已经更新了我的plunker,你能检查并更正吗?我更新了我的plunker,但它仍然不工作,你能检查我的plunker并告诉我丢失了什么吗@Aman您能否具体说明您面临的问题,或者使用收到的错误消息更新您的问题。我的问题是,在我的代码中,我无法在将来将“最小日期”设置为30天,“最大日期”设置为30天。我在指定“最小日期”和“最大日期”值时添加了“日期选项”。并且已经更新了我的plunker-现在可以使用了,谢谢@Aman
 $scope.toggleMin = function() {
        var date = new Date();
        date.setDate((new Date()).getDate() - 30);
        $scope.minDate = date;
      };
      $scope.toggleMin();

    //  Add this for maxDate, no code was there in plunker
    var date1 = new Date();
    date1.setDate((new Date()).getDate() + 30);
    $scope.dateOptions.maxDate = date1;