material icon indicating copy to clipboard operation
material copied to clipboard

input 'pattern' validation and input 'required' validation with ng-message not working when user types too fast

Open Charlie-Ng opened this issue 11 years ago • 3 comments

If the user types so fast, it will break the ng-message animation and the message doesn't show up anymore even if the input is not valid. This seems an issue after upgrading to 0.10.0.

I tried not to include the .css link and it solved the validation problem but also disabled the animation. Thank you.

Browsers: Chrome and Firefox.

http://plnkr.co/edit/CI1oHUJwKZqVEO78yJZo?p=preview

demos

Charlie-Ng avatar Aug 21 '15 00:08 Charlie-Ng

Change handlers need debouncing.

ThomasBurleson avatar Sep 04 '15 03:09 ThomasBurleson

I just manually updated your plunker to use the latest version of Material and Angular 1.4.7 and I believe this issue has been resolved.

If you still see the issue after upgrading, please post a comment here and we will reopen.

topherfangio avatar Nov 03 '15 05:11 topherfangio

Hi,

I had the same problem with a ng-pattern on a input field, with a regular expression valid for 12 or 14 caracters length only, and it was not corrected using the 1.4.8 angular version. If I type too fast, sometimes the field remains shown as invalid even when it has 14 caracters. Note that I'm not using material so this is only an issue from angular validation.

I think this is because the validation function is called via "attr.$observe" which uses a promise, thus is aynchronous. When I type too fast, the validation of the 13th caracter is probably sometimes called after the one of the 14th caracter, thus the field is marked as valid and then overrided by invalid. (see https://github.com/angular/angular.js/blob/d077966ff1ac18262f4615ff1a533db24d4432a7/src/ng/directive/validators.js line 31)

The solution I found is to delay the validation using ng-model-options and debounced : https://docs.angularjs.org/guide/forms#non-immediate-debounced-model-updates

I wait 100ms before launching the validation, it prevents the validation function from being called too many times and sometime in disorder. But this is not a very clean solution as I cannot be sure of the delay when the $observe promise will be resolved (even if hopefully it will be far less than 100ms).

JulReb avatar Dec 23 '15 16:12 JulReb