diff --git a/src/js/uppercaseOnly-directive.js b/src/js/uppercaseOnly-directive.js index ee07dd5..c4bca73 100644 --- a/src/js/uppercaseOnly-directive.js +++ b/src/js/uppercaseOnly-directive.js @@ -1,9 +1,9 @@ angular.module('focaDirectivas') - .directive('uppercaseOnly', [ + .directive('input', [ function() { return { - restrict: 'A', - require: 'ngModel', + restrict: 'E', + require: '?ngModel', link: function(scope, element, attrs, ctrl) { function parser(value) { @@ -19,14 +19,17 @@ angular.module('focaDirectivas') } function formatter(value) { - if (ctrl.$isEmpty(value)) { + if (ctrl.$isEmpty(value) || typeof value !== 'string') { return value; } return value.toUpperCase(); } - ctrl.$formatters.push(formatter); - ctrl.$parsers.push(parser); + if(attrs.type === 'text') { + + ctrl.$formatters.push(formatter); + ctrl.$parsers.push(parser); + } } }; }