Skip to main content
Participating Frequently
August 12, 2019
Question

Resetting a line of form fields with multiple resets per page, and on spawned pages

  • August 12, 2019
  • 3 replies
  • 1944 views

Hi..newbie to the forums as well as javascript in a pdf. I have a pdf with some very specific functionality...One of the pages has a form, with 10 different rows of data that each have their own reset button per line (illustrated below). In addition to that, this same page has a button which is supposed to duplicate this same form page again (with different fieldnames) so the user can enter an additional 10 lines of data, then click that same button to spawn yet another new page if needed, and so on and so on. As shown, each row consists of 7 input boxes, then a 4 option radio button set, then 2 more inputs, then another 6 option radio set. As if that wasn't enough, each of the individual radio button COLUMNS, and the last 2 input field COLUMNS, get tallied and totaled at the bottom, and those 'total' numbers each have to also be carried through (no matter how many of these pages the user spawns), and that total total has to appear on yet ANOTHER page of the file in a 'total total total' summary field. So, I'm good with spawning the new pages, but my problem at the moment is trying to get the individual reset buttons to only reset their own rows, and only on their own pages. I haven't even gotten to dealing with the totaling issue yet. I've tried to keep the field names small and consistent (ie the names in the 1st row are 1a, 1b, 1c, etc through 1k). Any help would be greatly appreciated!

My spawn new page button js so far is:

var SpawnPage = this.getTemplate({cName: "Template1"});

SpawnPage.spawn({nPage: pageNum + 1, bRename: true, bOverlay: false});

SpawnPage.setFocus(pageNum++);

and I've tried various unsuccessful variations for the resets js so I'm turning to experts:)

This topic has been closed for replies.

3 replies

Participating Frequently
August 19, 2019

It took me quite a while, but I finally figured out the 1st part of the issue (the single line resets on spawned pages). Now, I'm trying to figure out the summation issues.

So now what I'm trying to do is:

1. search for any fields that end with meta-total1 (ie P1.Template1.metatotal1, P2.Template1.metatotal1, P3.Template1.metatotal1 etc)

2. find the value that has already been calculated in that field (from a previous calculation)

3. add each of those numbers, plus an extra field named "differentlyNamedField" (meaning that is NOT spawned from a template page so will have a single name), and then add/total all of these values in a field called "Total Summary"

I feel like it should be fairly straightforward but it's not working for me for some reason. Any help appreciated!

try67
Community Expert
Community Expert
August 19, 2019

Can you post your code? Also, what does "it's not working" means, exactly? Is it producing no results at all? If so, are there error messages in the JS Console? Is it producing the wrong results?

Participating Frequently
August 19, 2019

So I kept at it, and the following is as far as I've gotten (and I'm by no means sure I'm even on the right track):

var field;

for ( var i = 0; i < this.numFields; i++) {

    field = this.getField(this.getNthFieldName(i));

var cnt = field.name.indexOf("T1.meta-total1");

if (cnt > 0 && field.value.length != "")

    {

      console.println(field.value);

    }

}

So I had generated/spawned a few pages to test this, and filled out the areas to generate some numbers, and was able to successfully print those numbers to the console. But what I need to do is add/sum those numbers to print that total to a new field. Also, to be explicit, the 'T1.meta-total1' is the 'template-name.fieldname', and I need to add up from P7.T1.meta-total1 to P[as many pages as the user generates].T1.meta-total1.

try67
Community Expert
Community Expert
August 12, 2019

The names of the spawned fields are predictable if you know the name of the template, the page number to which the page was spawned and the name of the original fields. This should allow you to create a script that resets only the desired fields, based on the name of the fields that triggers the action.

Bernd Alheit
Community Expert
Community Expert
August 12, 2019

Following gives an error:

SpawnPage.setFocus(pageNum++);

try67
Community Expert
Community Expert
August 12, 2019

That's because setFocus is a method of a Field object, not a Template.

I think what they were trying to do is:

this.pageNum = this.pageNum+1;

Or

this.pageNum++;

Participating Frequently
August 12, 2019

Thanks both for responding to this part. I was aware of this error, but it still seemed to function by setting the focus correctly. Try67 did you mean it should be the following?

var SpawnPage = this.getTemplate({cName: "T1"});

SpawnPage.spawn({nPage: pageNum + 1, bRename: true, bOverlay: false});

this.setFocus(pageNum++);

because that still gives an error (though does still set the focus on the new page as desired).