ngx-bootstrap icon indicating copy to clipboard operation
ngx-bootstrap copied to clipboard

Datepicker triggers ControlValueAccessor change without user interaction

Open rschlimmer opened this issue 1 year ago • 6 comments

Bug description:

The datepicker triggers the change event callback handler (e.g. ngModelChange) during component initialization.

Plunker/StackBlitz that reproduces the issue:

https://stackblitz.com/edit/1hchts-ei6y7y?file=src%2Fapp%2Fapp.component.ts

The provided StackBlitz renders two bsDatepicker that illustrate different initial model values. Both of their ngModelChange callback functions are immediately called without user interaction as seen in the console log. Additionally, the value provided by the event is strictly equal to the original model value despite being notified of a change. Lastly, clearing a datepicker that is currently assigned to a Date value triggers two change events; one notifying of the change to undefined and a second which re-notifies of the change to undefined.

This is a new issue since 18.0.0 of ngx-bootstrap. I believe the behavior change may have been introduced as an unintended side-effect of the fix for issue #6640 (pull-request #6641).

Versions of ngx-bootstrap, Angular, and Bootstrap:

ngx-bootstrap: 18.0.2

Angular: 18.1.4

Bootstrap:

Build system: Angular CLI, System.js, webpack, starter seed:

Expected behavior

The datepicker ControlValueAccessor implementation should invoke the callback function passed to registerOnChange only when changed by the component via user interaction.

Registers a callback function that is called when the control's value changes in the UI.

https://angular.dev/api/forms/ControlValueAccessor#registerOnChange

rschlimmer avatar Aug 14 '24 18:08 rschlimmer

I'm having a similar issue, since upgrading to v18.0.2, my project is getting stuck in infinite update loops in certain scenarios.

I've recreated the issue here: https://stackblitz.com/edit/stackblitz-starters-bznejv?file=src%2Fapp%2Fapp.component.html

kamran3210 avatar Aug 15 '24 09:08 kamran3210

I'm having same issue after upgrading to v18.0.2. As of now downgrading to v18.0.0 to keep the app running.

simfyz avatar Aug 22 '24 10:08 simfyz

same issue for me, had to downgrade like @simfyz mentioned.

M4x3e3e avatar Sep 06 '24 11:09 M4x3e3e

We're seeing this same issue with v12.0.0.

cca-developer avatar Sep 30 '24 20:09 cca-developer

Also confirming this issue. It causes a datepicker selection event to close the modal it's contained in.

Nvveen avatar Oct 15 '24 13:10 Nvveen

I am also facing the same issue on v18.0.2

LalitAgrawala004 avatar Oct 15 '24 17:10 LalitAgrawala004

Thanks for your report, this will be fixed soon!

lexasq avatar Oct 21 '24 15:10 lexasq

This issue still seems to occur in 18.1.2, fyi.

Nvveen avatar Oct 24 '24 14:10 Nvveen

@Nvveen fix is on the way for 18.1.3

lexasq avatar Oct 24 '24 14:10 lexasq