angularprimengp-calendar

PrimeNG p-calendar component with minDate issue when using formcontrol


I have upgraded my project from v15 to Angular v18/PrimeNG v17 and in my component:

                      <p-calendar
                        dateFormat="yy-mm-dd"
                        formControlName="finish_date"
                        [minDate]="today"
                      >
                      </p-calendar>

when I have date saved in DB and it is today or in the past, the field stays empty.

I want to minDate only for new inputs, but the field should display dates even in the past if already saved.


Solution

  • it is related to primeng V18 upgrade you can add the :

    [keepInvalid]="true" 
    

    attribute to the p-calendar component. This will help manage the minDate issue when using formControlName.

    <p-calendar
          dateFormat="yy-mm-dd"
          formControlName="finish_date"
          [minDate]="today"
          [keepInvalid]="true">
    </p-calendar>
    

    it will fix the issue