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
bug: ion-datetime
ngModel usage emits ionChange event without value change every time after initial load
#24452
Comments
Thanks for the issue! This issue has been labeled as In the meantime, please read our Winter Holiday Triage Guide for information on how to ensure that your issue is triaged correctly. Thank you! |
Hello @hatsantos thanks for reporting this issue! After further debugging, this issue only appears with You can see the different behaviors in this repo: https://github.com/sean-perkins/gh-24452-date-change There's an open PR that is working towards fixing some intertwined form issues with Angular and Ionic's form controls. In the interim, I would recommend using the reactive form control usage in your application to avoid the unnecessary event emission. I'll update this bug to reflect the issue with |
ion-datetime
ngModel usage emits ionChange event without value change every time after initial load
Hi everyone, I have a dev build that should resolve this issue: Please note that this is a build of Ionic 7 and is subject to the Ionic 7 Breaking Changes. |
…26083) resolves #20873 resolves #24452 BREAKING CHANGE - `ionChange` is no longer emitted when the `value` property of `ion-datetime` is modified externally. `ionChange` is only emitted from user committed changes, such as clicking or tapping a date. - Datetime no longer automatically adjusts the `value` property when passed an array and `multiple="false"`. Developers should update their apps to ensure they are using the API correctly.
Thanks for the issue. This has been resolved via #26083, and a fix will be available in an upcoming release of Ionic Framework. Please note that this fix requires a breaking change, so it is being targeted for the Ionic 7.0 release. Please feel free to continue testing the dev build, and let me know if you have any questions. |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out. |
Prerequisites
Ionic Framework Version
Current Behavior
I'm migrating an app from Ionic 5 to Ionic 6.
When using the ion-datetime component, the first time the component is used it works as aspected, the component does not dispatch the ionChange event when is open, it dispatch the event only after the first selection... but after a value is selected, if a click is done on the component (second time) a ionChange is dispatched without any change or selection.
Expected Behavior
The even should only be dispatched if a change occurs, for example, a different day is selected.
Steps to Reproduce
1 - Add a button/input to invoke the ion-datetime component in a modal with the default buttons on the ion-datetime component;
2 - Setup a ngModel and a ionChange event on the ion-datetime component;
3 - Do not set any value to the ngModel;
4 - Click on the component to invoke the ion-datetime modal;
5 - No ionChange event happens (that seems good);
5 - Selected a value and confirm the selected value;
6 - Value is updated and a ionChange event is dispatched;
7 - Click on the component to invoke the ion-datetime modal;
8 - An ionChange event happens, with out any selection, change other user interaction (new day selected);
And example can be installed from here: https://github.com/hatsantos/Ionic6DateTimeIonChangeBug
I added console logs and a loading screen with a 2 seconds delay when the ionChange is dispatched.
Code Reproduction URL
https://github.com/hatsantos/Ionic6DateTimeIonChangeBug
Ionic Info
Ionic:
Ionic CLI : 6.18.1 (C:\Users\hsantos\AppData\Roaming\nvm\v14.18.2\node_modules@ionic\cli)
Ionic Framework : @ionic/angular 6.0.1
@angular-devkit/build-angular : 13.1.2
@angular-devkit/schematics : 13.1.2
@angular/cli : 13.1.2
@ionic/angular-toolkit : 5.0.3
Capacitor:
Capacitor CLI : 3.3.2
@capacitor/android : 3.3.3
@capacitor/core : 3.3.3
@capacitor/ios : 3.3.3
Utility:
cordova-res : not installed globally
native-run : 1.5.0
System:
NodeJS : v14.18.2 (C:\Program Files\nodejs\node.exe)
npm : 6.14.15
OS : Windows 10
Additional Information
No response
The text was updated successfully, but these errors were encountered: