Don't repopulate the Date , Mate.

Feb 02, 2018

Copy link to clipboard

Copied

I have a field that populates a date when the form is created. I dont want it to repopulate every time the PDF opens after that.

My code:

var f = this.getField("ExamDate");

f.value = util.printd("mm/dd/yyyy)", new Date());

How do I do the null check?

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

A simple way to check for an empty field is to test for an empty string

if(f.value != "")

    f.value = util.printd("mm/dd/yyyy)", new Date());

This also works the same

if(f.value.length)

    f.value = util.printd("mm/dd/yyyy)", new Date());

This is the one I use cause it ignores entered spaces

if(/^\s*$/.test(f.value))

    f.value = util.printd("mm/dd/yyyy)", new Date());

However, now you have the issue of keeping a clean form available for opening. What happens when someone saves it back to the same name? No more blank form. You'll have to manually reset it and save it back.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

100

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

Don't repopulate the Date , Mate.

Feb 02, 2018

Copy link to clipboard

Copied

I have a field that populates a date when the form is created. I dont want it to repopulate every time the PDF opens after that.

My code:

var f = this.getField("ExamDate");

f.value = util.printd("mm/dd/yyyy)", new Date());

How do I do the null check?

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

A simple way to check for an empty field is to test for an empty string

if(f.value != "")

    f.value = util.printd("mm/dd/yyyy)", new Date());

This also works the same

if(f.value.length)

    f.value = util.printd("mm/dd/yyyy)", new Date());

This is the one I use cause it ignores entered spaces

if(/^\s*$/.test(f.value))

    f.value = util.printd("mm/dd/yyyy)", new Date());

However, now you have the issue of keeping a clean form available for opening. What happens when someone saves it back to the same name? No more blank form. You'll have to manually reset it and save it back.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

101

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
Feb 02, 2018 0
Adobe Community Professional ,
Feb 02, 2018

Copy link to clipboard

Copied

A simple way to check for an empty field is to test for an empty string

if(f.value != "")

    f.value = util.printd("mm/dd/yyyy)", new Date());

This also works the same

if(f.value.length)

    f.value = util.printd("mm/dd/yyyy)", new Date());

This is the one I use cause it ignores entered spaces

if(/^\s*$/.test(f.value))

    f.value = util.printd("mm/dd/yyyy)", new Date());

However, now you have the issue of keeping a clean form available for opening. What happens when someone saves it back to the same name? No more blank form. You'll have to manually reset it and save it back.

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...
Feb 02, 2018 0
Adobe Community Professional ,
Feb 02, 2018

Copy link to clipboard

Copied

Besides checking the value of the field, one can test the  default value of the field and set the value of default field. This approach will keep the open date if the form is cleared or reset by JavaScript of any menu option. To set the form up for saving with the date field cleared one only needs to clear the "Default value" on the options tab.

var oField  = this.getField("ExamDate");

if(oField.defaultValue = "")

{

      oField.devaultValue = util.printd("mm/dd/yyyy)", new Date());

     oField.value = oField.defautlValue;

     oField.readonly = true;

}

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...
Feb 02, 2018 2
Adobe Community Professional ,
Feb 02, 2018

Copy link to clipboard

Copied

Nice variation!! However, if you set the default value then a reset will never clear the date, and you can never get a new date on a clean form. The strategy for this really needs to be thought out. I think this type of document script only works when you have a clear form delivery system. If people are just copying it from a shared drive it should have a Form Prep button that clears the form and sets the current date.

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...
Feb 02, 2018 1
Feb 12, 2018

Copy link to clipboard

Copied

Thank you !!!!

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...
Feb 12, 2018 0
Feb 13, 2018

Copy link to clipboard

Copied

My code looks like this:

var f = this.getField("ExamDate");

if(f.value != "") 

     f.value = util.printd("mm/dd/yyyy)", new Date());

Its at the document level but the date is still updating. 

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...
Feb 13, 2018 0
Most Valuable Participant ,
Feb 13, 2018

Copy link to clipboard

Copied

You want to update the field if the value is not empty? That doesn't make much sense...

I think you want to update it if it is empty. If that's the case, change the second line of your code to:

if (f.valueAsString == "")

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...
Feb 13, 2018 0
rwiamacy LATEST
Feb 13, 2018

Copy link to clipboard

Copied

HA!!!!!! Thank yoooooooooouuuuuuuu!!!!!

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...
Feb 13, 2018 0