【发布时间】:2021-04-07 22:19:04
【问题描述】:
我有一个表单,其中有一个条件需要的 datepicker 元素。我无法使用任何值启动此元素,因为用户必须输入它。日期选择器格式为 dd/mm/yyyy。问题是在我添加ng-required 之前它工作正常。在元素中添加ng-required 条件后,当用户单击日历时,日历默认日期为 1969 年 12 月 31 日。用户将该日期更改为当前日期非常不方便。我尝试在日期选择器选项中将默认日期设置为今天,但没有运气。
<div class="form-group col-md-3 required" ng-show="decision==true">
<label class="control-label">Test Date</label>
<div class="input-group">
<input name="testDate" type="text" class="form-control" datepicker-popup="dd/MM/yyyy" ng-model="testDate" is-open="dpOpened.testDateTo"
close-text="Close" onfocus="this.blur();" datepicker-options="dateOptions" ng-required="decision==true" required/>
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="datepickerPopup($event, 'testDateTo')">
<i class="glyphicon glyphicon-calendar"></i>
</button>
</span>
</div>
</div>
--controller.js--
$scope.datepickerPopup = function($event, opened) {
$event.preventDefault();
$event.stopPropagation();
$scope.dpOpened[opened] = true;
}
$scope.dateOptions = {
showWeeks : false,
defaultDate : new Date()
};
$scope.dpOpened = {
testDateTo : false,
};
$scope.today = function() {
return new Date();
}
【问题讨论】:
标签: angularjs datepicker angular-ui-bootstrap