These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

setFocus problem on continuation page from Template

devrag
Registered: May 12 2010
Posts: 32
Answered

I have a two page Acroform with a button which runs script to add a continuation page from a template. The page adds just fine.

The problem is that in my JS, I try to setFocus to the textfield on the continuation page. But nothing happens. The page is added, but my view doesn't move. I don't think any field has focus. Here is my continuation button code from Page1:

// make sure a continuation page has not already been added.

if (this.getField("continuationAdded").value == "Off") {

var contPage = this.getTemplate("continueTemplate");
contPage.spawn( {
nPage:1,
bRename:false,
bOverlay:false
} );

// set checkbox so another continuation page can't be added.
this.getField("continuationAdded").value = "Yes";

// set the page numbers at the bottom of the pages. This is working, so I know
// I have gotten this far in my script.
this.getField("txtPg1PgTotal").value = "3";
this.getField("txtPg3PgNum").value = "3";
this.getField("txtPg3PgTotal").value = "3";

// setFocus to the textfield on Page2.
this.getField("db_contin").setFocus();

// In desperation also tried other names that might work.
// this.getField("db_contin1").setFocus();
// this.getField("db_contin#1").setFocus();
}

The text field on Page 2 (continuation page from template) is db_contin. When I look at the field name in the fields panel, it is listed as "db_contin#1". Since I don't understand why these numbers are being generated, I tried a few different names for the field to setFocus. No luck.

Anyone have an idea why I can't set Focus?

Thanks,
Devra

My Product Information:
Acrobat Pro 9.3.1, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Because the form field exist as 'db_contin1#0' on the hidden template, but the form field still exist. Look at the Navigation panel for the form fields. As long as the template remains hidden you can not access the first widget of that field.

Have you tried just showing the template?

Use of the renaming option prevents duplication of form field names.

George Kaiser

devrag
Registered: May 12 2010
Posts: 32
Thank you for responding and please indulge me a bit more, as I am confused by your first paragraph.

Although I named the field db_contin, when the template is generated, the field name becomes db_contin#1. And now it makes sense that it would rename the field, in case I tried to spawn a second template. But within my javascript, first I spawn the template, then I try to setFocus. And I have tried the field name "db_contin#1" without success. Shouldn't the field exist right after the page is spawned?

I am also confused by your sentence about "showing the template." Could you please explain what that means. Obviously, this is all very new to me.

My sincere thanks,
Devra
try67
Expert
Registered: Oct 30 2008
Posts: 2399
Since you specified not to rename the fields when spawning the page, Acrobat creates a new widget for each field. If you'll read the text describing the use of widgets in the Acrobat JavaScript Scripting Reference (under the Field object), you will see that the correct way to access them in a script is with a dot, followed by the widget's index number.

So the field you see as "db_contin#1" should be accessed like so:
this.getField("db_contin.1")

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

devrag
Registered: May 12 2010
Posts: 32
That's it! And thank you so much for the specific reading reference in the JavaScript Scripting Reference. More pieces are beginning to fall into place.

And thanks for taking the time to respond. This forum is the best!