Commit 365c7ff9fdb0342509d825dbd434f6698b6a4bd3
Exists in
master
Merge branch 'develop' into 'master'
Develop See merge request !10
Showing
1 changed file
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 | + }); |