primefaces / primeng

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

CheckBox Button - FormControl value is being updated twice when used with Reactive Forms #9608

Open agugan opened 3 years ago

agugan commented 3 years ago

I'm submitting a

[x] bug report

Current behavior

CheckBox form values are updated twice when used with reactive forms.

I think it is because along with registerOnChange, we have formControl.setValue being called explicitly when used with Reactive forms.

updateModel(event) {
....
            this.onModelChange(this.model);

            if (this.formControl) {
                this.formControl.setValue(this.model);
            }
}
 ....
  registerOnChange(fn: Function): void {
        this.onModelChange = fn;
    }

Expected behavior

CheckBox form values should be updated only once when used with reactive forms.

Minimal reproduction of the problem with instructions https://stackblitz.com/edit/primeng-checkbox-bug

In the above stackblitz, if you check the console.log of formControl.valueChanges , you can see it is being logged twice.

Happy to help with a PR. Thanks for the awesome library.

jahanarun commented 3 years ago

@yigitfindikli I also face the same issue. Any update on this would be appreciated.

jahanarun commented 3 years ago

@yigitfindikli Any updates on this?

shybzzz commented 3 years ago

the same issue but with AutoComplete I would also much appreciate if this is fixed

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,

Ahmed-Hafez commented 2 years ago

@mertsincan Hi Mertsincan, I'm still facing the same issue.

DarioVincenzoDeSimone commented 8 months ago

I've found a potential fix for this bug by simply appending pipe(debounceTime(500)) to the valueChanges observable (edit milliseconds as you wish) While I acknowledge that this may not be a definitive solution, I hope it proves helpful.