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

Resetting a date field

Community Beginner ,
May 24, 2019 May 24, 2019

Copy link to clipboard

Copied

How do I reset a date field to blank with javascript?  I've tried field01.value = ""; but that doesn't work.

I have a checkbox, and if that box is checked, I want 2 date fields to be required.  I've tried field01.required = true; but that doesn't work.

If the user unchecks the box, I want the 2 date fields to be blanked out.

TOPICS
PDF forms

Views

2.4K

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

Community Beginner , May 29, 2019 May 29, 2019

Ok, I finally figured it out.  When I added the date field, in the General tab I used a "Name:" of "DateRangeFrom" and "DateRangeTo".  I formatted them, in the Format tab, with mm/dd/yyyy.  This resulted in them getting actual field names of "DateRangeFrom_af_date" and "DateRangeTo_af_date".  Not the names I had assigned.  This was very confusing and hard to nail down had it not been for discovering the JS Console while working in Adobe Acrobat Pro to console.println a bunch of stuff.

The followi

...

Votes

Translate

Translate
Community Expert ,
May 24, 2019 May 24, 2019

Copy link to clipboard

Copied

You don't access a field like that. You need to use the proper methods for it, like so:

this.getField("field01")

Then you would be able to access the field's properties and methods.

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 ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

Thanks try67; I've tried

this.getField("field01").value = "";

But that doesn't reset it.  What are the properties and methods of a date field?

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 ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

All properties and methods are listed in the Acrobat Javascript Reference.

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 ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

Assuming the field name is correct that should have worked. Are there any error messages in the JS Console?

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
Advocate ,
May 25, 2019 May 25, 2019

Copy link to clipboard

Copied

Another approach would be

this.resetForm(["field01"]) ;

or, if that appears too complicated, use

this.getField("field01").value = this.getField("field01").defaultValue ;

However, if this field is the result of a calculation, you'd have to check there too, that it proper resets.

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 ,
May 29, 2019 May 29, 2019

Copy link to clipboard

Copied

I have tried both of the approaches below, and still the date field does not get blanked out.

var fld07 = this.getField("DateRangeFrom");

var fld08 = this.getField("DateRangeTo");

//fld07.value = fld07.defaultValue;

//fld08.value = fld08.defaultValue;

this.resetForm(["DateRangeFrom"]);

this.resetForm(["DateRangeTo"]);

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 ,
May 29, 2019 May 29, 2019

Copy link to clipboard

Copied

Do these fields have a calculated value?

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 ,
May 29, 2019 May 29, 2019

Copy link to clipboard

Copied

LATEST

Ok, I finally figured it out.  When I added the date field, in the General tab I used a "Name:" of "DateRangeFrom" and "DateRangeTo".  I formatted them, in the Format tab, with mm/dd/yyyy.  This resulted in them getting actual field names of "DateRangeFrom_af_date" and "DateRangeTo_af_date".  Not the names I had assigned.  This was very confusing and hard to nail down had it not been for discovering the JS Console while working in Adobe Acrobat Pro to console.println a bunch of stuff.

The following code then works:

var fld07 = this.getField("DateRangeFrom_af_date");

var fld08 = this.getField("DateRangeTo_af_date");

fld07.value = "";

fld08.value = "";

Many thanks for the help.

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