7

I use this (PrimeFaces, Java, JSF):

<p:calendar id="popupCal" yearRange="c:c+1" lang="fr" required="true"
            requiredMessage="Date obligatoire" readonlyInput="true"
            navigator="true" pattern="dd-M-yyyy" locale="fr"
            showOn="both" value="#{commandeMB.commande.dateCmd}"
            mindate="#{commandeMB.todaysDate}" />

and as I wrote, I set readonlyInput to true.

I tested also readonly to true and both to true but no result, always the date can be changed.

Is it a bug?

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
begiPass
  • 2,124
  • 6
  • 36
  • 57

6 Answers6

6

If you want that user must not be able to change the value of the Calender Dates, just view it then use showOn="none" and readonly="true" in p:calender attribute, I have used it and its working (I'm using Primefaces 5.0 hope it works on all versions) :

Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
Shahnawaz
  • 61
  • 1
  • 3
1

readonly is used when you just allow user use panel to pick date and can not change date from input. If you want user can not change date, you have to use disabled attribute to do that.

If you want user can see date picker and can not change date, you can disable dateselectevent via:

<p:calendar onfocus="$('#ui-datepicker-div td').unbind();" readonly="true"/>
Rong Nguyen
  • 4,143
  • 5
  • 27
  • 53
1

Actually I've found the issue to be casing. In our app, it's readonlyInput and that's where it works. readOnlyInput does not.

0

With PF 3.4, this solution will:

  • Retain 1.0 opacity on a readonly text input field (i.e., don't dim opacity with disabled=true);
  • Remove the Datepicker class from the field;
  • Unbind events from the field.

(1) Create a function:

function setCalendarVis(readOnly) { if(readOnly) $('input:text').removeClass('hasDatepicker').unbind(); }

(2) Define a calendar component:

<p:calendar readonly="#{bean.readonly}" value="#{bean.datefield}" mode="popup"/>

(3) Call the function, for example, maybe via an ajax event on a p:databable:

<p:ajax event="rowDblselect" update="@form" oncomplete="setCalendarVis(#{bean.readonly});"/>

My app uses different styles for read and write capability: enter image description here

My use of unbind() is rather brute force. You can refine it to unbind only particular events.

Flame suit on!

J Slick
  • 929
  • 11
  • 17
-2

Just add [readonlyInput]="true" attribute in the input.

Example:

 <p-calendar [readonlyInput]="true">
Guillermo Cacheda
  • 2,162
  • 14
  • 23
-2

This is how I achieved read only behaviour:

<p-calendar [readonlyInput]="true" [showOnFocus]="false">
karu
  • 9
  • 4