This answer
got me the closest to implementing this correctly but as soon as my field sets the $invalid
key on the form (at least I think that's what it is) it erases the text inside my text box
Asked
Active
Viewed 46 times
0

Community
- 1
- 1
-
try compiling whole form `$compile(element.form)(scope)` instead of `$compile(element[0].form)(scope)` – Pankaj Parkar Feb 12 '15 at 20:43
-
thanks... but it doesnt work. try it out in my plnker link at "here's my plnk" – Brian Schermerhorn Feb 12 '15 at 20:46
-
I have added answer. Check if it is useful to you or not? – Pankaj Parkar Feb 13 '15 at 18:39
1 Answers
0
In order to work your directive, you need to add priority:1000
so that will get executes the code before any directive gets executed & other thing before compiling the DOM you need to remove directive attribute meta-validate
so that it will not execute while compiling. If you don't do that then you will get Maximum Call stack exceeds.
error.
Directive
myApp.directive('metaValidate', function ($compile) {
return {
restrict: 'A',
priority: 1000, //this setting is important to make sure it executes before other directives
compile: function compile(element, attrs) {
return {
pre: function preLink(scope, iElement, iAttrs, controller) { if(!element.attr('ng-maxlength')){
element.attr('ng-maxlength', '2');
element.removeAttr("meta-validate");
} },
post: function postLink(scope, iElement, iAttrs, controller) {
$compile(element)(scope);
}
};
}
};
});
Hope this could help you. Thanks.

Community
- 1
- 1

Pankaj Parkar
- 134,766
- 23
- 234
- 299