primefaces / primeng

The Most Complete Angular UI Component Library
https://primeng.org
Other
10.56k stars 4.61k forks source link

InputMask triggers value change event on blur #11566

Open DerStimmler opened 2 years ago

DerStimmler commented 2 years ago

I'm submitting a ...

[x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Plunkr Case (Bug Reports)

https://stackblitz.com/edit/github-6hugjj?file=src/app/app.component.html https://github-6hugjj.stackblitz.io

The console prints all value changes. Just type some letters and then blur the control. You can see that the last value gets printed two times.

Current behavior When blurring the input mask a change event gets fired although the value doesn't change.

Expected behavior The change event gets only fired when the value actually changes.

Minimal reproduction of the problem with instructions Use the stackblitz example above.

Or create a input-mask control via form builder and subscribe to the valueChanges observable on the form group.

What is the motivation / use case for changing the behavior? It should work properly.

Please tell us about your environment: Windows, Rider, yarn, Angular 13, PrimeNg 13.3.3

DerStimmler commented 2 years ago

I'm pretty sure the problem lies in this if statement:

https://github.com/primefaces/primeng/blob/6f54ae08ec5c34594ad237a462808b634a01ee51/src/app/components/inputmask/inputmask.ts#L393-L406

The focusText variable doesn't get updated properly and always contains the initial value. So when you change the input the first part of the statement will always be true. Therefore the change event gets triggered in the if statement body.

To fix the issue you could maybe just remove that part and only keep the second part of the if statement. Or you have to update the variable properly.

mertsincan commented 2 years ago

Hi,

So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation. If there is no improvement on this, can you reopen the issue so we can include it in our roadmap? Please don't forget to add your feedback as a comment after reopening the issue. These will be taken into account by us and will contribute to the development of this feature. Thanks a lot for your understanding!

Best Regards,

DerStimmler commented 2 years ago

Hi, this issue is still present in version 14.2.1. Here is a new example: https://stackblitz.com/edit/github-ejhueh?file=src/app/app.component.html https://github-ejhueh.stackblitz.io

@mertsincan I can't reopen the issue since I'm not a collaborator of this repo and haven't closed the issue by myself.

HughMungous777 commented 1 year ago

Just stumbled upon this issue while developing.

"primeng": "16.0.2"

Is this going to be fixed some day?

bretmcg commented 2 weeks ago

Unfortunately still seeing this issue in PrimeNG 17.18.10.