Skip to main content
Participant
August 10, 2023
Answered

Choose current and future dates only

  • August 10, 2023
  • 2 replies
  • 835 views

Hello everyone, I'm very new to fillable forms and I hope you can help. I've been researching about this for awhile now to no avail. Please help 😅

 

I have a text field property that's formatted to Date. What I want to do is for the user to be able to choose present and future dates only when they click on it. Is that possible at all and can you share some workaround or there's really no solution for that? 

 

Most grateful for your responses. Thank you.

This topic has been closed for replies.
Correct answer Nesa Nurani

You can try something like this as 'Validate' script of date field:

if(event.value){
 var currentDate = new Date();
 var enteredDate = util.scand("mm/dd/yyyy", event.value);

 currentDate.setHours(0, 0, 0, 0);
 enteredDate.setHours(0, 0, 0, 0);

 if(enteredDate < currentDate){
  app.alert("Please enter a current or future date.");
  event.value = "";}}

If the user doesn't enter a current or future date, it will pop alert and clear the field.

 

2 replies

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
August 10, 2023

You can try something like this as 'Validate' script of date field:

if(event.value){
 var currentDate = new Date();
 var enteredDate = util.scand("mm/dd/yyyy", event.value);

 currentDate.setHours(0, 0, 0, 0);
 enteredDate.setHours(0, 0, 0, 0);

 if(enteredDate < currentDate){
  app.alert("Please enter a current or future date.");
  event.value = "";}}

If the user doesn't enter a current or future date, it will pop alert and clear the field.

 

Participant
August 10, 2023

OMG THANK YOU! It worked perfectly. I'm so grateful. Thank you so much Nesa!!

Amal.
Legend
August 10, 2023

Hi there

Hope you are doing well and thanks for reaching out.

The workflow you are trying to achieve might be possible using JavaScript. For more information, please check the help pages listed below:
https://acrobatusers.com/tutorials/javascript_console/
https://helpx.adobe.com/acrobat/using/applying-actions-scripts-pdfs.html

Hope it will help

Regards
Amal