From ff4f683623cec52261f4ca7308f8e90a5526ecb6 Mon Sep 17 00:00:00 2001 From: Jose Pinto Date: Thu, 14 Feb 2019 11:41:23 -0300 Subject: [PATCH] fix escribir en input text --- src/js/uppercaseOnly-directive.js | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/src/js/uppercaseOnly-directive.js b/src/js/uppercaseOnly-directive.js index 8f8c3e8..4cab819 100644 --- a/src/js/uppercaseOnly-directive.js +++ b/src/js/uppercaseOnly-directive.js @@ -2,36 +2,19 @@ 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(); - } + link: function(scope, element, attrs, modelCtrl) { if(attrs.type === 'text' && !attrs.readonly && !attrs.disabled && !attrs.uibDatepickerPopup) { - ctrl.$formatters.push(formatter); - ctrl.$parsers.push(parser); + modelCtrl.$parsers.push(function(input) { + return input ? input.toUpperCase() : ''; + }); } + + element.addClass('text-uppercase'); } }; } -- 1.9.1