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

Explorer ,
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

58

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
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , 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);

 

 

 

 

Likes

Translate

Translate
Adobe Community Professional ,
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.

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
community guidelines
Explorer ,
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.

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
community guidelines
Adobe Community Professional ,
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);

 

 

 

 

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
community guidelines
Explorer ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Thank you, Nesa. Appreciate the help.

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
community guidelines
Adobe Community Professional ,
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");
}

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
community guidelines
Explorer ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

LATEST

Thank you, JR for the help.

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
community guidelines
Adobe Community Professional ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

1.

 

Capture_575.png

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
community guidelines