Commit 0ee69c7d9d072d07da1a5c8f60e35a059fb77f88

Authored by Jose Pinto
1 parent 8b7b406fd5
Exists in master

aplico uppercaseOnly a todos los input text

Showing 1 changed file with 9 additions and 6 deletions   Show diff stats
src/js/uppercaseOnly-directive.js
1 1 angular.module('focaDirectivas')
2   - .directive('uppercaseOnly', [
  2 + .directive('input', [
3 3 function() {
4 4 return {
5   - restrict: 'A',
6   - require: 'ngModel',
  5 + restrict: 'E',
  6 + require: '?ngModel',
7 7 link: function(scope, element, attrs, ctrl) {
8 8  
9 9 function parser(value) {
... ... @@ -19,14 +19,17 @@ angular.module('focaDirectivas')
19 19 }
20 20  
21 21 function formatter(value) {
22   - if (ctrl.$isEmpty(value)) {
  22 + if (ctrl.$isEmpty(value) || typeof value !== 'string') {
23 23 return value;
24 24 }
25 25 return value.toUpperCase();
26 26 }
27 27  
28   - ctrl.$formatters.push(formatter);
29   - ctrl.$parsers.push(parser);
  28 + if(attrs.type === 'text') {
  29 +
  30 + ctrl.$formatters.push(formatter);
  31 + ctrl.$parsers.push(parser);
  32 + }
30 33 }
31 34 };
32 35 }