如何在日期模型小於當前日期或日期「已過期」時禁用每個日期選擇器。如果日期小於當前日期,則禁用ui引導日期選擇器 - Angularjs ngRepeat
我正在開發一個用於開始和結束日期的帶有datepickers的UI。最初,取決於從後端返回的數據,UI可以根據需要具有儘可能多的日期選擇器。用戶還可以添加更多日期選擇器。
以下是我用於使用ngRepeat
構建datepickers的示例數據。
{
"id": 1234,
"seasons": [{
"endDate": "2016-01-03",
"startDate": "2015-09-10",
"description": "2015"
}, {
"endDate": "2017-01-03",
"startDate": "2016-09-10",
"description": "2016"
}]
}
我正在創建一個用戶界面,用戶只有在開始日期和結束日期未過期的情況下才可以通過datepickers更改日期。在日期已過期的情況下,需要禁用日期選擇器。
我目前的做法是迭代季節數組,並檢查startDate是否小於今天。
ss.datePickerStartDateEnabled = false;
angular.forEach(ss.seasonSet.seasons, function(season, key) {
if (season.startDate < today) {
console.log('Less than today');
ss.datePickerStartDateEnabled = true;
}
});
到目前爲止它的工作原理,但它禁用不少於今天的startDate。
這裏是我的html
<div class="row" ng-repeat="s in ss.seasonSet.seasons track by $index">
<div ng-controller="DatePickerCtrl as datePicker">
<div class="col-md-3"> <!-- StartDate datepicker-->
<div class="form-group has-feedback">
<label for="username">Start Date</label>
<input
type="text"
class="form-control"
id="startDate{{$index}}" <!-- id=startDate1 -->
uib-datepicker-popup="{{}}"
ng-model="s.startDate"
is-open="datePicker.isOpen.startDate"
datepicker-options="datePicker.dateOptions"
ng-required="true"
ng-disabled="ss.datePickerStartDateEnabled"
close-text="Close"
ng-click="datePicker.open($event, 'startDate')"/>
<span class="form-control-feedback glyphicon glyphicon-calendar"></span>
</div>
<div class="form-group has-feedback">
<label for="username">End Date</label>
<input
type="text"
class="form-control"
id="endDate+{{$index}}"
uib-datepicker-popup="{{}}"
ng-model="s.endDate"
is-open="datePicker.isOpen.endDate"
datepicker-options="datePicker.dateOptions"
ng-required="true"
close-text="Close"
ng-click="datePicker.open($event, 'endDate')"/>
<span class="form-control-feedback glyphicon glyphicon-calendar"></span>
</div>
</div>
</div>
</div>
在我的控制器在日期選擇器輸入我怎樣使用id="endDate+{{$index}}"
與ng-disabled="ss.datePickerStartDateEnabled"
和ss.datePickerEndtDateEnabled
沿基於從上面的條件來禁用一個日期選擇器。
還有其他需要我做的驗證,例如重複日期和開始日期必須在上一個結束日期之後。我試圖首先解決這個簡單的案例。
在此先感謝。這裏是猛擊code,這裏是UI,日期時間選擇器不起作用。看到它全屏更好的用戶界面。
感謝您的反饋。 Suing'ng-disable'是正確的方法。我很快就會提出我的解決方案。 –