-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ngbDatePicker is only capturing the previous value when [ngModelOptions]="{ updateOn: 'blur' }" #2976
Labels
Milestone
Comments
Could you please provide a stackblitz with the minimal reproduction scenario? |
@maxokorokov here you go: I literally just added [ngModelOptions]="{ updateOn: 'blur' }" in the sample you referenced. |
maxokorokov
added a commit
to maxokorokov/ng-bootstrap
that referenced
this issue
Jan 23, 2019
maxokorokov
added a commit
to maxokorokov/ng-bootstrap
that referenced
this issue
Jan 23, 2019
pkozlowski-opensource
pushed a commit
that referenced
this issue
Jan 28, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug description:
Consider this standard snippet of code:
It creates a datepicker inside a popup, this is what it looks like with my custom styling:
![image](https://user-images.githubusercontent.com/43896758/51385202-9c3a7380-1b2f-11e9-858f-903d94b77037.png)
When you set the following option: [ngModelOptions]="{ updateOn: 'blur' }", ngbDatepicker does not behave correctly when you select a date from the popup, the value of the model is not the latest value you select, but the previous one selected just before it. And the slightly sinister part is that the latest value you just selected appears correctly in the input field as you would expect, so you would have no clue that the value of the model underneath is different.
Upon investigation it seems to be an issue with how ngbDatepicker implements ControlValueAccessor. When you select a date from inside the popup, ngbDatepicker fires the "touched" event BEFORE it fires the "change" event, and therefore upon the "touched" event angular updates the model to the old value before the new value has been captured with the "change" event. If that makes sense.
Versions:
Angular: 7.0.0
ng-bootstrap: 4.0.1
Bootstrap: 4.2.1
The text was updated successfully, but these errors were encountered: