Commit 7106e47c8911eaeada44613e896f92366f4b8ea3
1 parent
5375d8212b
Exists in
master
Directiva limite de numeros
Showing
1 changed file
with
25 additions
and
0 deletions
Show diff stats
src/js/limiteNumerosMax-directive.js
... | ... | @@ -0,0 +1,25 @@ |
1 | +angular.module('focaDirectivas') | |
2 | + .directive('limiteNumerosMax', function(){ | |
3 | + return { | |
4 | + require: 'ngModel', | |
5 | + scope: true, | |
6 | + link: function(scope, element, attr, ngModel) { | |
7 | + ngModel.$parsers.push(function (value) { | |
8 | + return '' + value; | |
9 | + }); | |
10 | + | |
11 | + if (!ngModel) return; | |
12 | + function limiteNumerosMax(texto) { | |
13 | + if (texto) { | |
14 | + texto = texto.replace(/^0-9]/g, '') | |
15 | + .substring(0,attr.limiteNumerosMax); | |
16 | + | |
17 | + ngModel.$setViewValue(texto); | |
18 | + ngModel.$render(); | |
19 | + return texto; | |
20 | + } | |
21 | + } | |
22 | + ngModel.$parsers.push(limiteNumerosMax); | |
23 | + } | |
24 | + }; | |
25 | + }); |