Home > Enterprise >  Cant set min and max date of datetime picker for ionic
Cant set min and max date of datetime picker for ionic

Time:04-27

In my ion-datetime I have dates to select. These dates are the dates provided from a function that finds the next available dates for delivery.

Here we have the function that gets the dates then set our result:

let result = getValidDates()
let temp = []
result.forEach(res => {
        temp.push(res.getDate())
    }
this.min = result[0].toLocaleDateString()
this.max = result.slice(-1)[0].toLocaleDateString()
this.pickupdates = result

Then we have our component with the dayValues property which is the result from the above function:

<ion-datetime
  mode='md'
  presentation="date"
  [showDefaultButtons]="true"
  [dayValues] = "pickupdates"
  [min] = "min"
  [max] = "max"
>
</ion-datetime>

This then gives us the proper selectable dates. But those very same dates are the same dates that can be selected in the next month. Ive tried tried to limit this by adding the min and max properties, but this then breaks and bring up the error: "Cannot destructure property 'month' of 'parseDate(...)' as it is undefined." and "TypeError: Cannot read properties of undefined (reading 'month')"

In this case min and max would be:

min = "26/04/2022"
max = "02/05/2022"

but still brings up that error

CodePudding user response:

the reason is min date max date should be yyyy/mm/dd or mm/dd/yyyy to be brief min="04/26/2022" and max="05/02/2022"

  • Related