Skip to content

bug: passing max only causes ion-datetime is out of bounds #25833

Description

@RRGT19

Prerequisites

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.

example image

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.

example image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions