Vel*_*ear 12 javascript angularjs angular-ui angularjs-directive
我正在使用角度UI引导程序弹出日期选择器来构建一个指令,它将允许我在需要的地方添加日期选择器.
当我将其与uiMask指令结合使用时,当我选择日期时,输入中的值会被加扰.
这是我的HTML:
<p class="input-group">
<input type="text" class="form-control"
ui-mask="99/99/9999"
ng-model="ngModel"
ng-model="order.date"
datepicker-popup="MM/dd/yyyy"
is-open="opened"
datepicker-options="dateOptions"
date-disabled="disabled(date, mode)"
ng-required="true"
close-text="Close" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open($event)">
<i class="glyphicon glyphicon-calendar"></i>
</button>
</span>
</p>
Run Code Online (Sandbox Code Playgroud)
我的JS:
/**
* DATE PICKER
*/
$scope.today = function () {
$scope.dt = new Date();
};
$scope.today();
$scope.clear = function () {
$scope.dt = null;
};
// Disable weekend selection
$scope.disabled = function (date, mode) {
return (mode === 'day' && (date.getDay() === 0 || date.getDay() === 6));
};
$scope.toggleMin = function () {
$scope.minDate = $scope.minDate ? null : new Date();
};
$scope.toggleMin();
$scope.open = function ($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.opened = true;
};
$scope.dateOptions = {
formatYear: 'yy',
startingDay: 1
};
$scope.initDate = new Date('2016-15-20');
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
$scope.format = $scope.formats[0];
Run Code Online (Sandbox Code Playgroud)
我希望能够使用ui-mask功能,通过不必输入/s 来简化输入日期.是否可以一起使用这些?
Igo*_*nzi 13
以下代码段对我有用:
.config(function ($provide) {
$provide.decorator('datepickerPopupDirective', function ($delegate) {
var directive = $delegate[0];
var link = directive.link;
directive.compile = function () {
return function (scope, element, attrs) {
link.apply(this, arguments);
element.mask("99/99/9999");
};
};
return $delegate;
});
});
Run Code Online (Sandbox Code Playgroud)
它只是用jquery.maskedinput.js提供的掩码装饰datepicker指令.玩得开心!
更新(2015年5月13日)
一个说明它工作的plunker:http://plnkr.co/edit/fTFNu9Mp2kX5X1D6AJOx?p=preview
| 归档时间: |
|
| 查看次数: |
9078 次 |
| 最近记录: |