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

Reset PDF Form

New Here ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

I have an acrobat form with 2 pages. Page 1 is interview questions with open-ended text boxes to record responses and page 2 has more interview questions, but the possible responses are in dropdown boxes instead of open-ended textboxes. A dropdown on page 2 ('Type') currently has a keystroke event to reset the entire form. Once you change the selection on this 'Type' dropdown, the entire document is reset. The keystroke event is :  

if (event.willCommit) this.resetForm()

 

I want to reset the dropboxes on page 2 only, but leave the textboxes on page 1 untouched. How do I do this in Javascript?

TOPICS
Acrobat SDK and JavaScript

Views

533

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 ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

As parameter of resetForm you can specify names of form fields.

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 ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

Inside an array, though. Like this:

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

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 ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

The code I am getting to run in the keystroke event is as follows:

if(event.willCommit) this.resetForm(["Dropdown.1"];

However, when I add more fields, such as dropdown2, etc, the code stops working. For example, this one is not working:

if(event.willCommit) this.resetForm(["Dropdown.1", "Dropdown.2"];

 

I even use hierarchical names to make the coding a bit easier, but no luck.

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 ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

Strange. Check the JS Console for error messages.

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 ,
Oct 08, 2020 Oct 08, 2020

Copy link to clipboard

Copied

I checked the console and it was OK. I figured it out however, thank you all so much. What happened was that I had other code on the form that was not completed properly, so it appeared as if the resetForm was not working, but it was working all along.

 

I had to add the following code to fix the problem:

else event.target.value = event.target.defaultValue;

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 ,
Oct 08, 2020 Oct 08, 2020

Copy link to clipboard

Copied

OK, I was rechecking the form again and I have another issue. I fixed the ResetForm issue as I said before. However, the other code is still problematic. Based on the value of the 'Type' field, I have dropdown boxes that I want changed to N/A. For example, if the type is Company, I want a dropdown box that is N/A to Companies to have N/A on the dropdown box automatically selected. With the code below in the custom calculation event of those drop boxes, I am able to do that:

 

var drop2 = this.getField("Type").value;

if (drop2 <= "4") event.value = "N/A";

 

However, when I change the type from Company to Individual, for example, (which then triggers the ResetForm() function), the N/A stays in the dropdown box. I want to make it so that the N/A is cleared from the dropdown and I can now select the correct response from the dropdown.

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 ,
Oct 08, 2020 Oct 08, 2020

Copy link to clipboard

Copied

You need to drop the quotes around "4" in your code...

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 ,
Oct 08, 2020 Oct 08, 2020

Copy link to clipboard

Copied

This still gives the same result, unfortunately. I was thinking that I need an 'else' statement after my 'if' statement. I am not sure what that statement would look like to however that would cause the N/A to go back to the default value (which is blank) so that the user can choose their own selection for the dropdown.

Or maybe I need a validation 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 ,
Oct 08, 2020 Oct 08, 2020

Copy link to clipboard

Copied

I still don't quite follow what you're trying to achieve here...

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 ,
Oct 08, 2020 Oct 08, 2020

Copy link to clipboard

Copied

I can explain it with a user case.

You are completing the form and you Select 'Company' as the type of customer. By selecting 'Company', you essentially eliminate some of the dropdown boxes on the form becuase some dropdown boxes do not related to companies. I do this by making the event.value = "N/A" in the calculation event of those specific dropdown boxes that I want to disregard for 'Company' type. The code I used to change the dropdown box to 'N/A' is: 

 

var drop2 = this.getField("Type").value;

if (drop2 <= 4) event.value = "N/A";

 

However, if when you are completing the form after you select 'Company' and you want to select 'Individual' as the new type instead, I have a ResetForm that triggers when you change the type. The code to reset is a custom keystroke event code on the 'Type' dropdown below:

 

if(event.willCommit) {

this.resetForm(["Dropdown"]);

}

 

This resets all of the dropdowns from that parent ("Dropdown") so that the user can enter new selections from the dropdown boxes.

The issue I have is that once I select a new type (change from 'Company' to 'Individual' etc), the dropdown boxes with the 1st code stays as 'N/A' and do not reset to their default value, but the dropboxes that do not have any code do reset to their default value.

Hope this helps.

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 ,
Oct 08, 2020 Oct 08, 2020

Copy link to clipboard

Copied

LATEST

The problem is the calculation 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 ,
Oct 08, 2020 Oct 08, 2020

Copy link to clipboard

Copied

I can't see the closing ).

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