[英]How to accept only date as input field value for bootstrap datepicker in angular
<form name="eventInformation" id="eventInformation"><label class="required"> Occurence Date </label>
<p class="input-group">
<input type="text" class="form-control" uib-datepicker-popup="{{format}}" ng-model="formData_EventDetails.eventOccurDate"
is-open="popup[0].opened" datepicker-options="dateOptions" close-text="Close" required/>
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open(0)"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
<div class="col-sm-2 pull-right">
<button class="btn btn-block btn-primary ebtn"
ng-disabled="eventInformation.$invalid"
ng-click="submit()">Save</button>
</div>
</form>
$scope.format = 'yyyy/MM/dd';
$scope.dateOptions = {
formatYear : 'yy',
startingDay : 1
};
$scope.popup = [];
for (i = 0; i < 10; i++) {
$scope.popup[i] = {
opened : false
};
}
$scope.open = function(i) {
$scope.popup[i].opened = true;
};
我有一個bootstrap datepicker元素,我試圖只接受日期作為輸入,但是它接受各種輸入,即字符串,數字等。我如何限制所以它僅將日期作為輸入
由於它是輸入文本框,因此您不能限制用戶輸入無效字符(默認行為)。
但是,當用戶提供錯誤的日期時,您可以停止模型更新操作(為此,您需要在輸入元素上設置以下屬性)
ng-model-options="{allowInvalid: false}"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.