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

Resetting a date field

Community Beginner ,
May 24, 2019 May 24, 2019

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
3.7K
Translate
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
1 ACCEPTED SOLUTION
Community Beginner ,
May 29, 2019 May 29, 2019
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.

View solution in original post

Translate
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 24, 2019 May 24, 2019

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.

Translate
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

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?

Translate
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

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

Translate
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

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

Translate
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

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.

Translate
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

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"]);

Translate
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

Do these fields have a calculated value?

Translate
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
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.

Translate
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