Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable future dates in angular p-calendar?

I'm using calendar input as follows.

<p-calendar  maxDate="dateTime" showTime="true" hourFormat="12" showButtonBar="true" [(ngModel)]="dateTime" name="timeOfUse" required #timeOfUse="ngModel">
          </p-calendar>

I want to disable future dates in this datepicker. It may be a simple property, but I can't figure it out. Appreciate any help

like image 512
Channa Avatar asked Jan 05 '18 18:01

Channa


People also ask

How do I turn off future date in calendar?

How do I restrict future dates in Datepicker? To disable future dates in JQuery date picker, we need to set the maxDate property. maxDate : 0 then all the future dates will be disabled. maxDate : '+1w' then all the future dates after a week will be disabled.

How to disable future date in angular?

To disable past and future dates, we can use min and max properties in Datepicker input text with matInput attribute. If only past dates need to be disabled, configure only min property. If only future dates need to disabled, configure only max property.

How do you turn off future date in date range picker?

daterangepicker({ autoUpdateInput: false, locale: { cancelLabel: 'Clear', format: 'DD-MM-YY' } });

How can I disable past dates in angular p calendar?

To disable specific dates and/or dates first set the readonlyInput to true so that the user cannot enter the dates using the keyboard. Now disable the dates using the disabledDates property and/or disable days using the disabledDays property.


2 Answers

You're not so far ! Just add square brackets to maxDate and it will work :

<p-calendar  [maxDate]="dateTime" showTime="true" hourFormat="12" showButtonBar="true" [(ngModel)]="dateTime" name="timeOfUse" required #timeOfUse="ngModel">
</p-calendar>

And if you want to disable dates 3 days after today for instance :

export class AppComponent {

   dateTime = new Date();

   constructor() {
     this.dateTime.setDate(this.dateTime.getDate() + 3);    
   }


}
like image 90
Antikhippe Avatar answered Oct 10 '22 20:10

Antikhippe


Found this on web might help you,Read the topic Disable specific dates and/or days

Date Restriction

[maxDate]="maxDateValue" 

https://www.primefaces.org/primeng/#/calendar

Reference

https://forum.primefaces.org/viewtopic.php?f=35&t=49578

like image 35
Nisal Edu Avatar answered Oct 10 '22 20:10

Nisal Edu