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

How to create a RESET button for selected fields with a confirmation message?

Contributor ,
Jul 19, 2022 Jul 19, 2022

Hello!

Need help. I have created a fillable PDF with 2 pages.

What I want is to have a Reset button for each page that only clears PDF fields on that page with a confirmation if they wish to continue before the actual clearing of the PDF fields.

Example:

Let us assume that on Page 1, I have the following PDF fields:

F01001

F02002

F02003

F03005

And on Page 2, I have the following PDF fields:

G03004

G03007

G06009

G07001

The Reset button on Page 1 should clear only those PDF fields on Page 1. The same with the Reset button on Page 2.

I wish that before actually clearing these PDF fields (either on Page 1 or Page 2), it would first ask the question, “Do you wish to continue (Y/N)?” Only if the answer is Y will the clearing of PDF fields on that page will proceed.

Thank you in advance.

TOPICS
JavaScript , PDF forms
4.5K
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 Expert ,
Jul 19, 2022 Jul 19, 2022

Sorry, I thought you wanted to clear fields on specific pages.

Use this in a button:

 

 

var resetTheseFields = ["F01002","F01005"];
var alert = app.alert("Are you sure you wish to delete fields on this page?",0,2);
if(alert == 4)
this.resetForm(resetTheseFields);

 

 

 

 

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 ,
Jul 19, 2022 Jul 19, 2022

Use this as 'Document level script':

function resetFieldsOnPage(doc, p){
var fields = [];
for (var i=0; i<doc.numFields; i++) {
var f = doc.getField(doc.getNthFieldName(i));
if(f==null) continue;
if(fields.indexOf(f.name)==-1 && ((typeof f.page=="number" && f.page==p) || (typeof f.page=="object" && f.page.indexOf(p)!=-1)))
fields.push(f.name);}
return fields;}

Then use this in a 'reset' button as 'Mouse UP' event:

var alert = app.alert("Are you sure you wish to delete fields on this page?",0,2);
if(alert == 4){
var cFields = resetFieldsOnPage(this, 0);
this.resetForm(cFields);}

(this, 0) will reset fields on first page since first page is numbered 0, on second page change 0 to 1, on 3rd change to 2...etc.

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
Contributor ,
Jul 19, 2022 Jul 19, 2022

Hi Nesa,

 

Thank you for replying to my concern.

 

Two questions:

 

1) Where can I define the Document level script?

 

2) What if I only want selected PDF fields on a certain page to be cleared and not all the PDF fields?

In the samples I have provided, I only want to clear F02002 and F02005. How can can I do this?

 

Thanks again.

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 ,
Jul 19, 2022 Jul 19, 2022

Sorry, I thought you wanted to clear fields on specific pages.

Use this in a button:

 

 

var resetTheseFields = ["F01002","F01005"];
var alert = app.alert("Are you sure you wish to delete fields on this page?",0,2);
if(alert == 4)
this.resetForm(resetTheseFields);

 

 

 

 

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
Contributor ,
Jul 20, 2022 Jul 20, 2022

Thank you, Nesa. Appreciate 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
New Here ,
Sep 28, 2022 Sep 28, 2022

Hello, I am trying to clear specific cells in my form and have tried this script. I am definitely not a programmer so there's that. Trying to clear cells S1 to S12 in a form using this:    

var resetTheseFields = ["S1,S12"];
var alert = app.alert("Are you sure you wish to delete fields on this page?",0,2);
if(alert == 4)
this.resetForm(resetTheseFields);

I get the "Are you sure you wish to delete fields on this page?" but the cells do not clear. Appreciate your help.

Thanks,

Max

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 ,
Sep 28, 2022 Sep 28, 2022

It doesn't work like that. You have to specify each field name separately, in quotes, or you could use a loop to populate the array of field names, since they are consistent, like this:

var resetTheseFields = [];

for (var i=1; i<=12; i++) resetTheseFields.push("S"+i);

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
New Here ,
Sep 28, 2022 Sep 28, 2022

Thank you for the quick reply. I will give this a try.

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
Contributor ,
Sep 28, 2022 Sep 28, 2022

If you don't want to use the loop solution provided by TRY67 and want to clear each and every PDF fields, try this script...

 

var alert = app.alert("("Are you sure you wish to delete fields on this page?\nDo you want to continue?"",0,2);
if(alert == 4){
this.resetForm("S1");
this.resetForm("S
2");
this.resetForm("S3");

this.resetForm("S4");
this.resetForm("S5");
this.resetForm("S6");
this.resetForm("S7");
this.resetForm("S8");
this.resetForm("S9");
this.resetForm("S10");
this.resetForm("S11");
this.resetForm("S12");
this.resetForm("S6");
this.resetForm("S6");
this.resetForm("S6");
this.resetForm("S6");
this.resetForm("S6");
this.resetForm("S6");
this.resetForm("S6");
this.resetForm("S6");


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 ,
Sep 29, 2022 Sep 29, 2022

Why the duplicated lines at the end? Also, if you want to do it like that, it's easier to combine it to a single command, like this:

this.resetForm(["S1", "S2", "S3", "S4"]); // etc.

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
Contributor ,
Sep 29, 2022 Sep 29, 2022

Thanks for the correction TRY67.

 

I opted to make each PDF field a line item because it is easy for me to extract and paste the PDF fields in the script.

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 ,
Sep 29, 2022 Sep 29, 2022

OK, just be aware that each reset command triggers all the calculation scripts in the file, so if you do it like that it could cause a significant delay.

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
Contributor ,
Sep 29, 2022 Sep 29, 2022

Thanks for this reminder.

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
New Here ,
Sep 29, 2022 Sep 29, 2022

This discussion is great and I am very appreciative. Last night I was unsuccessful in getting the suggestion by try67 to work and I think I have an idea why. this is a timesheet I built a few years ago. I have a few subforms within this form to complete various calculations. Frankly amazed I built this considering my level of knowledge. Step away from this stuff for a few years and I have to start over again. I think I need to include the subform path to make this work. Trying this and still no joy. This evening or tomorrow morning I will try other suggestions in this string and report back. Again thanks!

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 ,
Sep 29, 2022 Sep 29, 2022
LATEST

Subforms? Is this an LCD document? If so, all of the above might not apply, as LCD files have their own scripting model, different (although similar in some aspects) to that of "normal" PDF files.

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 ,
Jul 19, 2022 Jul 19, 2022

2.

Use this script:

 

var alert = app.alert("Are you sure you wish to delete fields on this page?",0,2);
if(alert == 4){
this.resetForm("F02002");
this.resetForm("F02005");
}


Acrobate du PDF, InDesigner et Photoshopographe
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
Contributor ,
Jul 20, 2022 Jul 20, 2022

Thank you, JR 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
Community Expert ,
Jul 19, 2022 Jul 19, 2022

1.

 

Capture_575.png


Acrobate du PDF, InDesigner et Photoshopographe
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