2015-05-12 163 views
3

當前嘗試使用標準日期選擇器,但將其與輸入掩碼結合,以便用戶更容易手動輸入日期。帶輸入掩碼的UI-Bootstrap datepicker

See Plunk

目前最大的問題是,當我補充面具的發生兩種情況之一,無論是手動輸入的日期到現場不工作(只要我完成它刪除值含義從現場)它成功地更新模型值,但當我打開datepicker它設置爲年1500

該plunk具有輸入的蒙版和非蒙版版本。

HTML

<input type="text" class="form-control" datepicker-popup="MM/dd/yyyy" ng-model="dt" is-open="opened" min-date="'2010-01-02'" max-date="dt" ng-required="true" close-text="Close" show-weeks="false" show-button-bar="false" ui-mask="99/99/9999" /> 
<button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button> 

JS

.controller('DatepickerDemoCtrl', function ($scope) { 
    $scope.dt = new Date(); 

    $scope.open = function($event) { 
    $event.preventDefault(); 
    $event.stopPropagation(); 

    $scope.opened = true; 
    }; 
}); 

回答

0

你不需要面具的API會爲你

<input class='form-control' data-provide='datepicker' data-date-format='yyyy-mm-dd'> 
+2

有時,用戶想在日期選擇器中輸入文本框而不是使用鼠標。 – Blaise

0

的DateTimePicker主做是解決

jQuery('#datetimepicker_mask').datetimepicker({ 
timepicker:false, 
mask:true, // '9999/19/39 29:59' - digit is the maximum possible for a cell 
}); 

http://xdsoft.net/jqplugins/datetimepicker/