Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

How to prevent user to enter data in "Date/Time Field"?

Avatar

Level 4

Hi folks,

     Back after long time to the forums, where I get answers which are helpful in making me good at utilizing designer.

     I am trying to validate the "Date/Time Field" using JavaScript but couldn't get a proper RegEx expression for various invalid user input formats. If anyone can help me out in finding a proper script that would Great.

     My script grown bigger and bigger to accepting invalid dates, but felt like hardcoding. So, instead I decided why can't we prevent a user to enter data into "Date/Time Field" and use only calendar dropdown. Is there is a way to do this?

find my sample testing docment

https://acrobat.com/#d=mYXkrhO2txuEesCfmvxNXg

Thanks in Advance,

Rajesh

4 Replies

Avatar

Not applicable

Hi Rajesh,

I don't think there is a way of stopping the user from using the keyboard to enter a date.  You can use the following script in the change event to stop them typing a date but they will still be able to paste a date in.

if (xfa.event.change.length === 1)

{

xfa.event.change = "";

}

This code works because if the date is selected from the calendar dropdown then the date xfa.event.change value will be the whole date and therefore longer than one character.

I couldn't access your sample but if you were to set an display picture for the date field to something other than date{YYYY-MM-DD} then a valid date will have a formattedValue that is different than the rawValue.

Dave

Avatar

Level 2

Hi All,

Please note this worn't work in XFA 3.3 (Reader 10.1) as there is a bug that restricts the change event from being overwritten. http://forums.adobe.com/message/3956926#3956926

Kind Regards

Kev

Solutions Architect

Avoka

Avatar

Level 4

Thank You Dave and Kavin,

Dave, find the working copy https://acrobat.com/#d=Gcr*icvepRfzXAqEHYwL5A

hmm, that is bad, to hear, Kavin, a bug. so there is any by pass that we can make the above scripting work in Reader 10.1?

Please let me know.

Once again thanks,

Rajesh

Avatar

Level 2

Hi Rajesh

It will work in Reader 10.1 if the compatibility is set to anything else than "Reader 10 and above" as this will use a different rendering agent. The bug only exists in XF3.3

Sorry for any confusion.

Kind Regards

Kev