p calendar readonly not working in primeng

2.5k Views Asked by At

<p-calendar readonly="true" [showTime]="true" inputId="time" [hourFormat]="24" [minDate]="minDate" [maxDate]="tomorrow" inputId="range" [(ngModel)]="obj.date" formControlName="selectedDateTime">

3

There are 3 best solutions below

0
Anderson Benício On BEST ANSWER

Readonly property doesn't exist in p-calendar. You can use the "disabled" property instead.

    <p-calendar 
    disabled="true" 
    [showTime]="true" 
    inputId="time" 
    [hourFormat]="24" 
    [minDate]="minDate" 
    [maxDate]="tomorrow" 
    inputId="range" 
    [(ngModel)]="obj.date" 
    formControlName="selectedDateTime"></p-calendar>
0
Rajesh K On

Use [readonlyInput]="true" instead of readonly="true"

Note - readonlyInput when specified, prevents entering the date manually with keyboard. Default value is null

Reference - https://www.primefaces.org/primeng/showcase/#/calendar

0
ProgIn On

I think when readonlyInput is true must be showOnFocus false Please see link https://github.com/primefaces/primeng/issues/10880