Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear Date Selection using Primefaces Calendar

Is there any way to clear the date selection using prime faces calendar?

<p:calendar pattern="MM/dd/yyyy" navigator="true" id="endDate" for="endDate"
readonlyInput="true" mindate="#{manageMarketingProgramsBean.currentDate}" showOn="button">
<f:convertDateTime pattern="MM/dd/yyyy" timeZone="America/New_York" />
</p:calendar>

I have readonlyInput="true" because I dont want user to type the date. I force them to pick the date from the calendar, there needs to be another way to provide user the ability to clear the date selected. Please let me know how can I achieve this?

like image 917
Sri Avatar asked Jan 16 '23 14:01

Sri


2 Answers

The first approach that comes into my mind would be:

<p:calendar readonlyInput="true" widgetVar="calendarWidget"/>     
<p:commandButton value="Reset" onclick="calendarWidget.setDate(null)"/>   
like image 141
fischermatte Avatar answered Jan 18 '23 05:01

fischermatte


This worked for me

<p:calendar widgetVar="calendarWidget" pattern="MM/dd/yyyy" />     
<p:commandButton value="Reset" onclick="PF('calendarWidget').setDate(null)" 
type="button" />
like image 40
bahadir_g Avatar answered Jan 18 '23 05:01

bahadir_g