Commit ff4f683623cec52261f4ca7308f8e90a5526ecb6

Authored by Jose Pinto
1 parent e4431065bb
Exists in master

fix escribir en input text

Showing 1 changed file with 6 additions and 23 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',
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)) {
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 if(attrs.type === 'text' && 7 if(attrs.type === 'text' &&
28 !attrs.readonly && 8 !attrs.readonly &&
29 !attrs.disabled && 9 !attrs.disabled &&
30 !attrs.uibDatepickerPopup) { 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 }
36 }; 19 };