Commit 6dadcfc6e136a2d999f7281411286a57cec5d924
1 parent
0ee69c7d9d
Exists in
master
and in
1 other branch
correcion error uppercaseOnly en disabled y readonly
Showing
1 changed file
with
3 additions
and
1 deletions
Show diff stats
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', | 5 | restrict: 'E', |
| 6 | require: '?ngModel', | 6 | require: '?ngModel', |
| 7 | link: function(scope, element, attrs, ctrl) { | 7 | link: function(scope, element, attrs, ctrl) { |
| 8 | 8 | ||
| 9 | function parser(value) { | 9 | function parser(value) { |
| 10 | if (ctrl.$isEmpty(value)) { | 10 | if (ctrl.$isEmpty(value)) { |
| 11 | return value; | 11 | return value; |
| 12 | } | 12 | } |
| 13 | var formatedValue = value.toUpperCase(); | 13 | var formatedValue = value.toUpperCase(); |
| 14 | if (ctrl.$viewValue !== formatedValue) { | 14 | if (ctrl.$viewValue !== formatedValue) { |
| 15 | ctrl.$setViewValue(formatedValue); | 15 | ctrl.$setViewValue(formatedValue); |
| 16 | ctrl.$render(); | 16 | ctrl.$render(); |
| 17 | } | 17 | } |
| 18 | return formatedValue; | 18 | return formatedValue; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | function formatter(value) { | 21 | function formatter(value) { |
| 22 | if (ctrl.$isEmpty(value) || typeof value !== 'string') { | 22 | if (ctrl.$isEmpty(value) || typeof value !== 'string') { |
| 23 | return value; | 23 | return value; |
| 24 | } | 24 | } |
| 25 | return value.toUpperCase(); | 25 | return value.toUpperCase(); |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | if(attrs.type === 'text') { | 28 | if(attrs.type === 'text' && |
| 29 | !attrs.readonly && | ||
| 30 | !attrs.disabled) { | ||
| 29 | 31 | ||
| 30 | ctrl.$formatters.push(formatter); | 32 | ctrl.$formatters.push(formatter); |
| 31 | ctrl.$parsers.push(parser); | 33 | ctrl.$parsers.push(parser); |
| 32 | } | 34 | } |
| 33 | } | 35 | } |
| 34 | }; | 36 | }; |
| 35 | } | 37 | } |
| 36 | ]); | 38 | ]); |
| 37 | 39 |