-
Notifications
You must be signed in to change notification settings - Fork 27.4k
input does not watch ngPattern value for changes #5226
Comments
@caitp this is kind of related to the validation stuff that you've been working on elsewhere, would you like to take a look at this one as well? |
the tricky thing here is that we should revalidate when the pattern changes in addition to when the viewValue changes |
The thing with this is that currently the pattern doesn't come from a parsed expression / scope variable, it's just a string literal turned into a regexp, so watching for changes to that means essentially watching the DOM attribute value for change. I think I mentioned that on a different issue regarding this a few weeks ago. Watching changes to the actual DOM attribute is fairly different from what angular is typically doing. Watching the actual DOM attribute value also means that it's not really possible to unwatch constant expressions, which is kind of sad. So, there are ways to do it, but I'm not totally sure about them being good ideas. If it's a green light for breaking change, then that's one thing, but otherwise I'm not too sure about it. |
The pattern does come from a scope variable when ng-pattern is "var" instead of "/regexp/". I'm not changing the DOM in my example above. |
+1 |
I think it would be very useful to allow binding to ng-pattern. Perhaps make it a standalone directive as suggested above. |
+1 |
It actually does that in >= 1.3.x: http://plnkr.co/edit/QNX5dXmRsBMYlMle9LHH Enter some characters from A-Z -> model is set. Then clichk switch, and the model will be invalidated. |
If you use input ng-pattern="var" with $scope.var = some regexp, and then you change that regexp in a handler, the validation doesn't react until the user modifies the field.
I'm working around this by using this hack:
var c = angular.element(document.getElementById('id')).controller('ngModel');
c.$setViewValue(c.$viewValue);
The text was updated successfully, but these errors were encountered: