I wrote custom AngularJS directive that dynamically adds ng-pattern and do some other stuff.
It works, but in Chrome and Internet Explorer, if the user tries to enter chars in the middle of existing string, the cursor jumps to the end of the string. In Firefox it works fine.
(Tested with Chrome 44, Firefox 40, IE 11)
HTML:
<input type="text" name="input1" ng-model="value1" validation-directive>
JS:
myApp.directive("validationDirective", function ($compile) {
return {
restrict: 'A',
link: function (scope, element) {
element.removeAttr('validation-directive'); // necessary to avoid infinite compile loop
element.attr("ng-pattern", new RegExp("^[a-z]{0,10}$"));
//Do more stuff...
$compile(element)(scope);
}
};
});
Why does it happened? And who can I fix that?
Thanks!
$validatorsobject, but if this is good enough for you maybe you can provide a fiddle?