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

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

Contributor ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

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

Views

2.0K

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

 

 

 

 

Votes

Translate

Translate
Community Expert ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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

 

 

 

 

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

Copy link to clipboard

Copied

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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


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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

Thanks for this reminder.

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

Copy link to clipboard

Copied

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!

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

Copy link to clipboard

Copied

1.

 

Capture_575.png

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