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

touched broken for matInput #11

Closed artem-v-shamsutdinov closed 6 years ago

artem-v-shamsutdinov commented 6 years ago

Hello,

Using ng-trim with Angular Material appears to break the setting of the "touched" property of the input.

Here is an example:

https://stackblitz.com/edit/angular-68fg1b?file=index.html

The field has an error message defined that should show if the field has the "required" error and has been touched. However the touched property does not get updated when I click on the field (or when I enter data into it).

I'll gather more info as I debug ...

Thanks, :)

artem-v-shamsutdinov commented 6 years ago

So, just injecting NgControl as a member variable into the directive appears to fix the problem. :)

Here is the working example:

https://stackblitz.com/edit/angular-vxfwnt

I did have to move providers to the module level and add a NG_VALIDATORS provider (as described here: https://stackoverflow.com/questions/39809084/injecting-ngcontrol-in-custom-validator-directive-causes-cyclic-dependency )

khashayar commented 6 years ago

@russoturisto Can this issue be closed or do you still facing any problems?

dankahle commented 6 years ago

This is still an issue. Not sure why you closed it. If you look at his stackblitz examples, it's easy to see. I just got the latest material and still happening. For some reason, his injecting NgControl into the constructor does the trick. It's one of several material issues. Several components have their own ControlValueAccessor and you can only have one of those, input[matAutoComplete] is one, and the code crashes on that, messes up my app at least. I put your opt out class on it and all worked fine with the rest of my inputs, but I notice that ngModel.touched isn't happening, so this is still an issue.