Reset a form - need help with javascript

New Here ,
Jan 06, 2020

Copy link to clipboard

Copied

Hello,

I created an action button that clears a form. I used the JS below that provides the user a warning before they clear the form. However, if they select "no" it still clears it. How do I fix it?

 

Here's what I have so far:

 

if( app.alert({
cMsg: "Are you sure you want to clear this form?",
cTitle: "Reset Form Warning",
nIcon: 2,
nType: 2
}) == 4) {
this.resetForm();
}

Adobe Community Professional
Correct answer by Lukas_Engqvist | Adobe Community Professional

Are you clearing the form and running the Javascript? If you have action to also clear form it will do both, which means clearing the form even if you press no here (and resetting it twice if you press yes). Remember you can have several events that trigger actions/scripts, so check that you don't have something happening on "Mouse Down", "Click" and/or "Mouse Up"

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms

Views

1.1K

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

Reset a form - need help with javascript

New Here ,
Jan 06, 2020

Copy link to clipboard

Copied

Hello,

I created an action button that clears a form. I used the JS below that provides the user a warning before they clear the form. However, if they select "no" it still clears it. How do I fix it?

 

Here's what I have so far:

 

if( app.alert({
cMsg: "Are you sure you want to clear this form?",
cTitle: "Reset Form Warning",
nIcon: 2,
nType: 2
}) == 4) {
this.resetForm();
}

Adobe Community Professional
Correct answer by Lukas_Engqvist | Adobe Community Professional

Are you clearing the form and running the Javascript? If you have action to also clear form it will do both, which means clearing the form even if you press no here (and resetting it twice if you press yes). Remember you can have several events that trigger actions/scripts, so check that you don't have something happening on "Mouse Down", "Click" and/or "Mouse Up"

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms

Views

1.1K

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
Jan 06, 2020 0
Adobe Community Professional ,
Jan 06, 2020

Copy link to clipboard

Copied

There is nothing wrong with this code. If the form is still being cleared, then there is something else going on.

Are there more actions associated with the button? Or other code in the script? Maybe something leftover from your initial development?

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
Reply
Loading...
Jan 06, 2020 0
Adobe Community Professional ,
Jan 06, 2020

Copy link to clipboard

Copied

Are you clearing the form and running the Javascript? If you have action to also clear form it will do both, which means clearing the form even if you press no here (and resetting it twice if you press yes). Remember you can have several events that trigger actions/scripts, so check that you don't have something happening on "Mouse Down", "Click" and/or "Mouse Up"

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
Reply
Loading...
Jan 06, 2020 0
New Here ,
Jan 07, 2020

Copy link to clipboard

Copied

Thanks that was it. I just needed to remove the duplicate "reset a form" action. Works perfectly now. 

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
Reply
Loading...
Jan 07, 2020 0
New Here ,
Jan 07, 2020

Copy link to clipboard

Copied

Cancelar

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
Reply
Loading...
Jan 07, 2020 0
New Here ,
Dec 28, 2020

Copy link to clipboard

Copied

Is there a way to target specific fields with this code? I dont want to clear everything.

I would like only to target dollar amounts in my form.

Thanks in advance

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
Reply
Loading...
Dec 28, 2020 0
try67 LATEST
Most Valuable Participant ,
Dec 29, 2020

Copy link to clipboard

Copied

Sure:

this.resetForm(["Field1", "Field2", "Field3"]);

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
Reply
Loading...
Dec 29, 2020 0