• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Drop Down Show and Hide Dates

Community Beginner ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

I am creating a form for our payroll department where a user will select the start date of a payroll period. The list of dates in the drop down box is large so I used http://www.acroscript.net/pdf/demos/comboPopulateTest.pdf to create the box. What I need to do is hide any dates that are old so the user selects a future date. All of the searches I have come across relate to dependent drop down boxes and cannot find any scripts to "filter" dates. Any help will greatly be appreciated. Solely using Acrobat XI.

Thank you

TOPICS
PDF forms

Views

620

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
community guidelines
Community Expert ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

What happens if the user selects a date and then opens the file later on? If you refresh the list of options each time it is opened you will delete any value that was selected in the past.

Votes

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
community guidelines
Community Beginner ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

Thank you. The form will be saved as read only so hopefully that will not be a problem

Votes

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
community guidelines
Community Expert ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

Unless you flatten your file, or add a condition not to update the field's options list when it is set as read-only, it will be.

Votes

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
community guidelines
Community Expert ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

That's George Johnson's PDF for filling a combobox with items from a pasted list.

Why don't you create a script for filling the dropdown with a list of relevant dates?

Here is a script that starts with today and goes for 30 days. Make sure you change the dropdown field name "DateList" to match the one on your form.

var aDateList = [];

var nToday = (new Date).getDate();   

var dtItem;

for(var i=0;i<30;i++)

{

  dtItem = new Date;

  dtItem.setDate(nToday + i);

  aDateList.push(util.printd("mm/dd/yyyy", dtItem));

}

this.getField("DateList").setItems(aDateList);

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Community Beginner ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

The dates will be 14 days apart. I used George Johnson's PDF because I was using dates calculated in Excel i.e. 14 days apart--using payroll dates e.g. 2/16/18. Thank you

Votes

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
community guidelines
Community Expert ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

easy enough to do. Just use this variation, it generates 10 dates 14 days apart, starting with today. If you put this script at the document level it will recreate the date list every time the document is opened, so it will always be current.

var aDateList = []; 

var nToday = (new Date).getDate();     

var dtItem; 

for(var i=0;i<10;i++) 

  dtItem = new Date; 

  dtItem.setDate(nToday + i*14); 

  aDateList.push(util.printd("mm/dd/yyyy", dtItem)); 

this.getField("DateList").setItems(aDateList); 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Community Beginner ,
Feb 06, 2018 Feb 06, 2018

Copy link to clipboard

Copied

Thank you for the reply. This is a fine script to add days from today, however, the pay periods are set with the next future one starting on 2/16/2018 then 3/2/2018 etc. On 2/17/2018 I need the first visible date to be 3/2/2018.

Votes

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
community guidelines
Community Expert ,
Feb 06, 2018 Feb 06, 2018

Copy link to clipboard

Copied

Well, the point of the script is to show how consecutive dates are created. All you have to do is modify the start point and the increment to whatever is needed.

Say for example the start date is in a form field. Then the script would parse the date out of the field.

Say for example the start date format was mm/dd/yyyy.

Here's a modified script to use a random start date.

var aDateList = [];  

var dtItem = util.scand("mm/dd/yyyy",this.getField("StartDate"));

if(dtItem)

{

     for(var i=0;i<10;i++)  

     {  
          dtItem.setDate(dtItem.getDate() + 14);  
          aDateList.push(util.printd("mm/dd/yyyy", dtItem));  

     }
}  
this.getField("DateList").setItems(aDateList);  

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Community Beginner ,
Feb 09, 2018 Feb 09, 2018

Copy link to clipboard

Copied

Thank you very much for the script. I'm obviously not familiar with java script. The above is setting the first date 14 days from today. The getDate() seems to be getting in the way. I am using:

var aDateList = [];    

var dtItem = util.scand("mm/dd/yyyy",this.getField("2/2/2018")); 

if(dtItem) 

     for(var i=0;i<10;i++)    

     {    

          dtItem.setDate(dtItem.getDate() + 14);

          aDateList.push(util.printd("mm/dd/yyyy", dtItem));    

     } 

}    

this.getField("DateList").setItems(aDateList);

Votes

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
community guidelines
Community Expert ,
Feb 09, 2018 Feb 09, 2018

Copy link to clipboard

Copied

LATEST

You are correct. I write this stuff pretty fast. So Here's quick change to make sure it starts with the date in the input field.

BTW: the getField is for gettting an actual field on the form, its not a way to specify a date. "StartDate" is a field name, not a placeholder for adding a date.

  1. var aDateList = [util.printd("mm/dd/yyyy", dtItem)];    
  2. if(dtItem) 
    1. var dtItem = util.scand("mm/dd/yyyy",this.getField("StartDate")); 
  3.      for(var i=0;i<10;i++)    
  4.      {    
  5.           dtItem.setDate(dtItem.getDate() + 14);    
  6.           aDateList.push(util.printd("mm/dd/yyyy", dtItem));    
  7.      } 
  8. }    
  9. this.getField("DateList").setItems(aDateList);    

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines