Reset date in a p:calendar

UI Components for JSF
pauga
Posts: 22
Joined: 03 Jun 2011, 08:49

11 Jul 2011, 12:48

Hi,

now i´m working with primefaces v3.M2. In my app I use p:calendar component as 'readonly' field. I have a problem with that, when users select a date, is imposible to unselect it ... i propose to add a button that clear the calendar, and unselect the previous date.

I found another problem with p:calendar, when click the 'today' button, ajax event doesnt´t work; only work fine when I select a date clicking over the number of the day.

Please help me out in this.

Thanks in advance

khizar
Posts: 5
Joined: 13 Apr 2011, 17:28

19 Jul 2011, 14:43

+1 for the clear button request
Primefaces 3.0M1 , JSF 2 , Apache Tomcat 6

gsouza
Posts: 5
Joined: 19 Aug 2010, 20:34

25 Aug 2011, 18:06

yeah!
i want this to!

pauga
Posts: 22
Joined: 03 Jun 2011, 08:49

01 Sep 2011, 10:31

have someone found any way to implement that????

Best regards.

palace
Posts: 25
Joined: 02 Jun 2010, 10:30
Location: Stockholm
Contact:

01 Sep 2011, 13:30

You have to make it not read-only for this to work right now. Can you make it not read-only? Should be more user-friendly then since users can just tab and enter the value directly. To clear the date you just submit an empty value
Primefaces 3.0.M3 with JSF 2.1.2 on Tomcat 7

pauga
Posts: 22
Joined: 03 Jun 2011, 08:49

13 Sep 2011, 11:38

I cannot make it not read-only, that is the problem

muwooer
Posts: 22
Joined: 23 Sep 2011, 03:54

25 Sep 2011, 10:40

I need this, too. Can someone add reset button to calendar?

ltune
Posts: 125
Joined: 20 Jul 2011, 20:25
Contact:

25 Sep 2011, 14:00

Should be more user-friendly then since users can just tab and enter the value directly.
You can initalize your Date member in construtor to the date you want and make the component readonly="true" (note in userguide: readonly, not "read-only")
and to prevent users to type anything use: readOnlyInputText="true". To be completely sure use minDate and maxDate to the Intialized value. :twisted:
Can someone add reset button to calendar?
You just add a simple p:commandbutton with update={calndars`id} and an action that resets the beanValue, (method: String yourMethod() in your Bean) Make sure to return null to prevent navigation. Ready. ;)

Stay tuned.

Adam
Busy applying primefaces patches to my local repo at /dev/null

george.gastaldi
Posts: 15
Joined: 26 Jan 2012, 16:58

19 Feb 2012, 20:44

Placing a button is not enough, there are screens which do not accept adding another button.

It should be allowed to render a "Clear" button or any custom button

MikeK
Posts: 104
Joined: 13 Oct 2010, 15:07

06 Apr 2012, 16:49

You can do this with Javascript.


Here is the code...

Code: Select all

 
<p:calendar value="#{property.propDate}" id="date" readOnlyInputText="true" pattern="MM/dd/yyyy" size="15" widgetVar="dateVar" />
                        <p:spacer width="10" />
                        <p:commandLink value="Clear Date" onclick="javascript:clearDate();" />
Here is the Javascript...

Code: Select all

function clearDate() {
    dateVar.setDate(null);
}
Alternative Javascript

Code: Select all

function clearDate() {
    document.getElementById("form1:date_input").value = "";
}
Prime Faces 6.2
Mojarra 2.2.14
Apache Tomcat 9.0
Internet Explorer 10,11

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 39 guests