khashayar / ng-trim-value-accessor

Angular's (missing) trim accessor to automatically trim values of input fields
MIT License
53 stars 19 forks source link

inputs(except those whose type is password) are always untouched #13

Closed mei-rong-ding closed 6 years ago

mei-rong-ding commented 6 years ago

We do the validation for the inputs, some are required. So we need to show error message if user click in and click out with nothing filled in. The input node has "ng-untouched" property, it should be changed to "ng-touched" after user click in, but it is not after using "ng-trim-value-accessor"

rahulp22 commented 6 years ago

I see the same happening as well. Once I add the TrimValueAccessorModule plugin class="ng-untouched" shows up for inputs that have had focus and then lost it. If I remove TrimValueAccessorModule, the inputs behave as expected on touch. Any suggestions as to how to fix this or when can we expect a fix? Thanks.

despian commented 6 years ago

I have submitted a PR which fixes this issue.

The problem is the directive is missing the host parameters which the DefaultValueAccessor directive has:

https://github.com/angular/angular/blob/6.0.6/packages/forms/src/directives/default_value_accessor.ts#L51-L56

Namely '(blur)': 'onTouched()'

There are some other host parameters there which are also missing. Not really sure what effect their absence has though.

If you want to fix this in your own project you can just create your own directive with the code from PR #20.