bug: passing max only causes ion-datetime is out of bounds
See original GitHub issuePrerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
Ionic Framework Version
- v4.x
- v5.x
- v6.x
- Nightly
Current Behavior
I have a field to select the date of birth. The rule is to start showing dates 10 years before today. In the meanwhile, the field should be empty until you select a date.
When setting the max
to 2012-08-26T12:47:01.977Z
or to 2012
, I receive this warning:
The value provided to ion-datetime is out of bounds.
Min: undefined
Max: {"month":8,"day":26,"year":2012,"hour":12,"minute":47}
Value: {"year":2022,"month":8,"day":26,"hour":8,"minute":56,"tzOffset":0}
I understand the warning and I see that the Value (2022) is greater than the Max (2012). It seems that the component is picking up the today Date automatically.
Trying to set the field’s value with the same max
date that I have provided, the warning disappears.
This can be confusing because the reality is that the user did not select a date yet. Also, when the user see that date, he can think that was automatically pulled from its account settings, which is false.
Expected Behavior
- The component should not take
today
date automatically. - If no Value exists, should render the dates taken into account min/max settings.
Steps to Reproduce
<ion-modal trigger="open-modal">
<ng-template>
<ion-content>
<ion-datetime
#datetime
size="cover"
[(ngModel)]="value"
max="2012-08-26T12:47:01.977Z"
[preferWheel]="true"
></ion-datetime>
</ion-content>
</ng-template>
</ion-modal>
Code Reproduction URL
No response
Ionic Info
Ionic:
Ionic CLI : 6.20.1
Ionic Framework : @ionic/angular 6.2.4
@angular-devkit/build-angular : 14.1.1
@angular-devkit/schematics : 14.1.1
@angular/cli : 14.1.1
@ionic/angular-toolkit : 7.0.0
Capacitor:
Capacitor CLI : 3.6.0
@capacitor/android : 3.6.0
@capacitor/core : 3.6.0
@capacitor/ios : 3.6.0
Utility:
cordova-res : 0.15.4
native-run : 1.6.0
System:
NodeJS : v16.16.0
npm : 8.18.0
OS : macOS Monterey
Additional Information
Maybe this behavior was intended and decided for some reason, but if this is the case, how can I accomplish a simple UX like the one I have described before?
My goal is to let the user select a date in the past while keeping the field/component with no initial value.
Issue Analytics
- State:
- Created a year ago
- Comments:13 (7 by maintainers)
Top GitHub Comments
Thanks for your response.
I confirm with that dev build that now is working as intended, no matter the datetime format you use.
Thanks a lot!.
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.