PrimeFaces calendar accepts invalid dates as input

UI Components for JSF
Post Reply
jonnyirving
Posts: 2
Joined: 07 Dec 2012, 15:48

07 Dec 2012, 16:13

The problem I am having is with the PrimesFaces 3.4.1 calendar. When using the popup date picker activated either through the button or on input field focus you can only select valid dates which work fine, happy days!

The issues comes when you manually add a date into the input field, if you add an invalid date the PrimeFaces calendar component takes its best guess at converting this into a valid date and then sending it, meaning that back-end validation is a no go. Some interesting translations below:

30/02/2012 becomes 2/6/2014
322/05/2012 becomes 5/10/2038
01/14/2012 becomes 4/1/2012

Same weirdness can be recreated on the PrimeFaces demo page.

I have seen solution around using the readOnlyInput='true' attribute but that only seems to prevent letters being entered in the field not number or slashes. Below is one instance of the calendar I have implemented, have I missed somthing silly? Apparently the PrimeFaces calendar used to be rock solid:

Code: Select all

<p:calendar id="fldDateOfBirth" value="#{pc_CreateUser.user.dateOfBirth}" binding="#{pc_CreateUser.dobComp}" navigator="true" pattern="dd/MM/yyyy" maxlength="10" yearRange="-100" validator="#{pc_CreateUser.validateDOB}" title="#{msg.user_date_format_default_tip}" converterMessage="#{msg.user_error_dob_invalid}" readOnlyInput="true" showOn="button" />
Any help would be greatly appreciated.

Similar question also asked on StackOverflow for future reference: http://stackoverflow.com/questions/1376 ... s-as-input

d34d_d3v1l
Posts: 193
Joined: 01 Nov 2012, 04:48

07 Dec 2012, 17:18

Yeah I noticed that aswell...

So what I did was:

Code: Select all

			<p:calendar id="date" value="#{data.value}" style="margin-left: 10px;" navigator="true" size="25" pattern="dd/MM/yyyy" showOn="button" >
				<f:convertDateTime pattern="dd/MM/yyyy"/>
			</p:calendar>
works good enough for me ! :)
INFO: Starting Servlet Engine: Apache Tomcat/7.0.12
INFO: Initializing Mojarra 2.1.10
INFO: Running on PrimeFaces 3.5
INFO: Running on PrimeFaces Extensions 0.6.1

jonnyirving
Posts: 2
Joined: 07 Dec 2012, 15:48

11 Dec 2012, 15:39

Hey that seems to have done the trick, thanks for your reply! :D

arjun@2022
Posts: 1
Joined: 24 Jan 2022, 18:04

24 Jan 2022, 18:14

How to populate invalid string in primeng calendar text box using the angular reactive form at run time? It's been long time I am trying out but didn't get any solution for that, Can any one please suggest is there any options available in prime ng side.

HTML code:

<p-calendar
formControlName="value" showTime="true" showSeconds="true" hourFormat="24"
dateFormat="dd/mm/yy" placeholder="DD/MM/YYYY" showIcon="true" showOnFocus="false"
appendTo="body" dataType="string" keepInvalid="true">
</p-calendar>

jepsar
Posts: 166
Joined: 03 Sep 2014, 11:41
Location: NL / BE
Contact:

25 Jan 2022, 12:49

This is the PrimeFaces forum. For PrimeNG questions, try the PrimeNG forum.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub: https://github.com/jepsar
Spotify: 90s Rave, Acid, Trance, House

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 14 guests