Manish
Manish

Reputation: 740

Allowing a certain range of dates dynamically in primefaces

I have used maxdate and mindate to select the dates dynamically for two date fields(from date and to date) using the below code-

<p:calendar id="FromDate" value="#{controller.fromDt}" showOn="button" 
    maxdate="#{controller.toDt}" >
       <p:ajax event="dateSelect" update="ToDate"></p:ajax>
    </p:calendar>

 <p:calendar id="ToDate" value="#{controller.toDt}" showOn="button"
     mindate="#{controller.fromDt}">
       <p:ajax event="dateSelect" update="FromDate"></p:ajax>
    </p:calendar>

Everything seems to work fine if a date is selected. The restrictions are applied to the other dependent calendar. Like if fromDate is set, then restrictions are applied to the todate. But once the fromdate is deleted using backspace or delete, still the restrictions are there in toDate field.

I understand that when the date is deleted, then it is not a dateSelect event, but even trying to place a valueChange event won't work because valueChangeEvent is triggered only when the page is submitted.

Can someone suggest me an idea how to solve this. Thanks in advance.

Upvotes: 4

Views: 3097

Answers (1)

Hatem Alimam
Hatem Alimam

Reputation: 10048

Simply add another p:ajax with a change event.

<p:calendar id="FromDate" value="#{controller.fromDt}" showOn="button" 
  maxdate="#{controller.toDt}" >
   <p:ajax event="dateSelect" update="ToDate"></p:ajax>
   <p:ajax event="change" update="ToDate"></p:ajax>
</p:calendar>

Upvotes: 6

Related Questions