Make maxDate
selectable as today at the latest (past days are clickable but not tomorrow). The range between minDay
and maxDay
should not exceed 365 days, allowing for fewer days to be selected.
$scope.dateOptions = {
formatYear: "yy",
minDate: getMinDate(),
maxDate: new Date(),
startingDay: 1
};
function getMinDate() {
var oldDay = new Date();
oldDay.setDate(oldDay.getDate() - 365);
return oldDay;
};
This restriction is insufficient. I want to set maxDate
as 1/03/2021, which should then allow selecting dates from 365 days ago up to 1/04/2020.
Additionally, a validation rule needs to be implemented where minDate
cannot be later than maxDate
.
Below is the relevant portion of HTML code:
<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>