JsDaddy / ngx-mask

Angular Plugin to make masks on form fields and html elements.
https://jsdaddy.github.io/ngx-mask
MIT License
1.14k stars 298 forks source link

The onChange is triggered when [mask] change even if the triggerOnMaskChange is false. Input becomes dirty when maskChanged. #1360

Open XHicoRVI opened 2 months ago

XHicoRVI commented 2 months ago

🐞 bug report

Is this a regression?

Yes, the previous version in which this bug was not present was: 16.2.4 ### Description The onChange is triggered when [mask] updating after init. Input becomes dirty when maskChanged. ## 🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-ivy-mask-qy4mdv?file=src%2Fapp%2Fapp.component.html

The problem comes from this behaviour : https://github.com/JsDaddy/ngx-mask/blob/develop/projects/ngx-mask-lib/src/lib/ngx-mask.service.ts#L526

The onChange is triggered when mask changed even if the triggerOnMaskChange is false.

The if (this.writingValue || (!this.triggerOnMaskChange && this.maskChanged)) should never trigger onChange. In the case in latest versions the function always call onChange if this.maskChanged is true.

If this is a wanted behaviour we need a configuration variable to choose if we want the onChange triggered when maskChanged.

🌍 Your Environment

Angular Version:


Angular CLI: 16.2.11
Node: 18.12.1
Package Manager: npm 9.8.1
OS: win32 x64

Angular: 16.2.12
... animations, cdk, common, compiler, compiler-cli, core, forms
... localize, material, material-moment-adapter
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1602.11
@angular-devkit/build-angular   16.2.11
@angular-devkit/core            16.2.11
@angular-devkit/schematics      16.2.11
@angular/cli                    16.2.11
@schematics/angular             16.2.11
ng-packagr                      16.2.3
rxjs                            7.8.1
typescript                      4.9.5
zone.js                         0.13.3