uppercaseOnly-directive.js
1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
angular.module('focaDirectivas')
.directive('input', [
function() {
return {
restrict: 'E',
require: '?ngModel',
link: function(scope, element, attrs, ctrl) {
function parser(value) {
if (ctrl.$isEmpty(value)) {
return value;
}
var formatedValue = value.toUpperCase();
if (ctrl.$viewValue !== formatedValue) {
ctrl.$setViewValue(formatedValue);
ctrl.$render();
}
return formatedValue;
}
function formatter(value) {
if (ctrl.$isEmpty(value) || typeof value !== 'string') {
return value;
}
return value.toUpperCase();
}
if(attrs.type === 'text' &&
!attrs.readonly &&
!attrs.disabled &&
!attrs.uibDatepickerPopup) {
ctrl.$formatters.push(formatter);
ctrl.$parsers.push(parser);
}
}
};
}
]);