Commit 8d59ecd6e058b98f0f19b4d495cde50745deec29
Exists in
master
Merge branch 'master' into 'develop'
Master See merge request !9
Showing
1 changed file
Show diff stats
src/js/limiteNumerosMax-directive.js
| File was created | 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 | }); | ||
| 26 |