【发布时间】:2021-08-30 23:25:12
【问题描述】:
我希望maxDate 最多可以选择今天,(过去应该可以点击,但明天不行)
我选择maxDay和minDay之间的天数最多应该是365天,不能选择超过365天,但是可以少选,
$scope.dateOptions = {
formatYear: "yy",
minDate: getMinDate(),
maxDate: new Date(),
startingDay: 1
};
function getMinDate() {
var oldDay = new Date();
oldDay.setDate(oldDay.getDate() - 365);
return oldDay;
};
这还不够,我只能设置从今天到 365 天之间的天数,
但如果我选择maxDate 作为 2021 年 1 月 3 日,我希望它是可选的,那么 minDate 应该在 365 天前可以选择,比如 2020 年 1 月 4 日 ..
我想做一个像minDate 这样的验证,不能晚于maxDate。
这里是html的相关部分,
<div class="row">
<div class="col-sm-3">
<label for="sel1">{{ 'LISTLOG_SEARCHSTARTDATE' | translate }}:
<!-- <a class="ion-information-circled" tooltip-animation="true" tooltip-placement="top" -->
<!-- uib-tooltip="{{'TOOLTIP_DEVICELOG_SEARCHDATE' | translate}}"></a> -->
</label>
<p class="input-group">
<input type="text" class="form-control" uib-datepicker-popup="{{format}}" ng-model="logVariables.startDate"
ng-change="formatDateModal()" ng-model-options="{timezone: 'UTC'}" is-open="popup1.opened"
datepicker-options="dateOptions" 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>
<div class="col-sm-3">
<label for="sel1">{{ 'LISTLOG_SEARCHENDDATE' | translate }}:
<!-- <a class="ion-information-circled" tooltip-animation="true" tooltip-placement="top" -->
<!-- uib-tooltip="{{'TOOLTIP_DEVICELOG_SEARCHDATE' | translate}}"></a> -->
</label>
<p class="input-group">
<input type="text" class="form-control" uib-datepicker-popup="{{format}}" ng-model="logVariables.endDate"
ng-change="formatDateModal()" ng-model-options="{timezone: 'UTC'}" is-open="popup2.opened"
datepicker-options="dateOptions" close-text="Close" alt-input-formats="altInputFormats" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open2()"><i
class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
</div>
</div>
【问题讨论】:
标签: javascript angularjs datepicker angularjs-validation