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

Default current date and time

Explorer ,
Feb 26, 2018 Feb 26, 2018

Copy link to clipboard

Copied

I am able to make the current date and time populate a field.  However, I would like for it to allow the user to enter a date and time, and if nothing entered then default to the current date and time.  Is this possible?

Current code I am using is this:

this.getField("CompTime").value = util.printd("mm/dd/yyyy HH:MM", new Date());

This gives me current date and time, but it cannot be changed.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

2.8K

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

correct answers 1 Correct answer

Explorer , Feb 27, 2018 Feb 27, 2018

It would be something outside of the form.  I don't have any way to tie something automated to the form to trigger the date/time to be entered other than a mouse click by the operator on the field itself. 

As an alternate:

Would there be a way to add a button at each time/date field that when pressed would enter the current time/date, otherwise the operator could click in the field and manually enter the time/date?

Votes

Translate

Translate
Community Expert ,
Feb 26, 2018 Feb 26, 2018

Copy link to clipboard

Copied

Yes, that's possible.  Your script is correct, where is it being used? In what script? And how? Do you want the date to remain unchanged after it is set to current?

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
Explorer ,
Feb 26, 2018 Feb 26, 2018

Copy link to clipboard

Copied

The script is in the form field "CompTime" under actions.  I would like the time to be able to be manually changed, if needed.

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 26, 2018 Feb 26, 2018

Copy link to clipboard

Copied

So right now you have it setup so that the current time is populated when the user clicks on the Field?  You're current script forces the field value to change and it cannot be overridden. This isn't going to work for the final script, which needs to keep the field the same when it contains a date value.

So to move forward, the first thing you need to do is to figure out the exact behavior of the field. Basically, what causes the field to be set to the current date? For example, it could be when the form is loaded, or anytime the field is blank. This is the starting point, then we can figure out how this can be safely overridden for manual entry.

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
Explorer ,
Feb 27, 2018 Feb 27, 2018

Copy link to clipboard

Copied

Thank you Thom. 

What I am building is a form that will be filled out during a manufacturing process.  There will be several places that there are start and end times for different steps taking place that the operator needs to enter.  The only reason that the operator would need to change the date/time would be if they forgot to enter the information at the time it was required, and had to go back and fill the time in later.

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 27, 2018 Feb 27, 2018

Copy link to clipboard

Copied

What is the initial trigger that causes the date to be entered in the first place?

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
Explorer ,
Feb 27, 2018 Feb 27, 2018

Copy link to clipboard

Copied

It would be something outside of the form.  I don't have any way to tie something automated to the form to trigger the date/time to be entered other than a mouse click by the operator on the field itself. 

As an alternate:

Would there be a way to add a button at each time/date field that when pressed would enter the current time/date, otherwise the operator could click in the field and manually enter the time/date?

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 27, 2018 Feb 27, 2018

Copy link to clipboard

Copied

Yes, this would be a good way to do it. You could also have a button for starting the entire process that would make sure the form is cleared was well as pre-filling fields like the current date. In either case the script you are already using works fine as a button script.

and you don't need anything special to allow the user to edit the field.

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
Explorer ,
Feb 27, 2018 Feb 27, 2018

Copy link to clipboard

Copied

LATEST

Thank you Thom, that worked.

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