Commit 989496c437d6f32151b8f41593f725bff1c2d797

Authored by Nicolás Guarnieri
Exists in master and in 1 other branch develop

Merge branch 'master' into 'master'

Master

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