KroneCorylus / ngx-colors

Simple yet elegant Material color picker for Angular
https:\\ngx-colors.web.app
MIT License
88 stars 24 forks source link

fix: control is not pristine in template driven forms #93

Closed xfh closed 10 months ago

xfh commented 1 year ago

Hi, thanks for sharing your color picker library.

I found a problem in the implementation of the ControlValueAccessor, which is most noticeable in template driven forms. When you bind a model value via a non-null default, the control (and thus the entire form) is not pristine. The problem is, that you are calling the onChange callback in the writeValue method. The onChange callback is supposed to be called when the view wants to update the model. See https://angular.io/api/forms/ControlValueAccessor#registeronchange

I've added some unit tests to highlight the problem and implemented a fix.

I wasn't sure about the projects code style, since tslint is demanding one style but implemented is another (e.g. quote marks). Let me know if you want me to adjust anything.