Highlighted

Restricting a User to Input a Date by Using the Calendar Only

New Here ,
Nov 09, 2020

Copy link to clipboard

Copied

Hello, I have a form where I've formatted all the date fields to be displayed as DD-MMM-YYYY. However, I noticed that users can still type in a date rather than picking from the drop-down calendar. This causes issues. For example, if a user decides to type in "1/9/2020" thinking it's Jan 1, 2020, they then quickly move on and fail to see that the form then reverts it to "01-Sep-2020". I'd like to restrict any type-in and only force the sure to use the calendar to pick the date. Is this possible? Thank you.

TOPICS
PDF forms

Views

23

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Restricting a User to Input a Date by Using the Calendar Only

New Here ,
Nov 09, 2020

Copy link to clipboard

Copied

Hello, I have a form where I've formatted all the date fields to be displayed as DD-MMM-YYYY. However, I noticed that users can still type in a date rather than picking from the drop-down calendar. This causes issues. For example, if a user decides to type in "1/9/2020" thinking it's Jan 1, 2020, they then quickly move on and fail to see that the form then reverts it to "01-Sep-2020". I'd like to restrict any type-in and only force the sure to use the calendar to pick the date. Is this possible? Thank you.

TOPICS
PDF forms

Views

24

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 09, 2020 0
Adobe Community Professional ,
Nov 09, 2020

Copy link to clipboard

Copied

The answer is yes and no, but it's tricky.  It is possible to create a script to block user input, but not the popup calendar input. However, there are several issues. First, the popup calendar is a feature of Acrobat Pro or Reader, not the PDF. So if this form is opened on any other PDF viewer, it will likely keep the user from entering any date.  Second, the formatting that makes the field a date field, is also where the script for blocking the user input needs to be. So entering it is tricky, and it can't be edited afterward. Its a forward only process. 

 

Here is what you do. 

Enter this line of code into the Custom Format script. This has to be done first. It is quite impossible to do it second.

AFDate_FormatEx("dd-mmm-yyyy");

 

Now enter this code into the Custom Keystroke script. Once this is done the field formatting will immediately convert to a custom date field and there will be no access to the custom scripts. 

AFDate_KeystrokeEx("dd-mmm-yyyy");
if(!event.willCommit)
    event.rc = /(^\d{2}\-\w{3}\-\d{4}$)?/.test(event.change);

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 09, 2020 1
New Here ,
Nov 10, 2020

Copy link to clipboard

Copied

Hmm, just tried, but doesn't seem to change anything on the field as I could still write in a date. I most likely will just revert the date formatting to US formatting rather than the EU. I'd rather have dates correct.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 10, 2020 0
Adobe Community Professional ,
Nov 10, 2020

Copy link to clipboard

Copied

Were any errors reported in the Console Window?

If entered correctly the keystroke script will prevent nearly all manual input into the field. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 10, 2020 0