Focus on opening

Avatar

Avatar

SciMax

Avatar

SciMax

SciMax

27-05-2009

Is it possible to automatically focus on a specific field when a LiveCycle PDF is opened? 

If yes, what script or formcalc and event type should I use?   And last, where do I put the event on the hierarchy?

I tried to put the following script in the first subForm on the body page 1 level.  Please note the object I want to focus on is part of a fragment.

xfa.host.setFocus("DeptDiv.ddlCityDept");

But I was blocked from doing so.  I get this error message and the entire Script Editor window was greyed out.

"The script is not editable because the Script Editor contains script that is in a fragment."

Any assistance would be really appreciated.

Thanks.

Accepted Solutions (0)

Answers (9)

Answers (9)

Avatar

Avatar

SciMax

Avatar

SciMax

SciMax

01-06-2009

Thanks everyone for your invaluable assistance.   I've got my form up and running, and the form owner is ecstatic with the end product.

Avatar

Avatar

SciMax

Avatar

SciMax

SciMax

29-05-2009

Occasionally. But not in this particular instance. ….b

Avatar

Avatar

Jono_Moore

Avatar

Jono_Moore

Jono_Moore

28-05-2009

That sounds weird - I keep the Script Editor open multi-line all the time on another monitor (along with most of the other palettes).

Avatar

Avatar

Stephanie_Legau

Avatar

Stephanie_Legau

Stephanie_Legau

28-05-2009

I know Paul answered your question, but just as an additional bit of info:

The error message

"The script is not editable because the Script Editor contains script that is in a fragment."

If the Script Editor is set to show all scripts, and some of the scripts it is showing are part of a fragment, then the entire editor is read-only.  Scripts that are part of fragments cannot be edited outside the fragment file; in order to prevent the editing, the Script Editor is set to read-only mode.

Ways to prevent this from bothering you while you work are to disable the "Show Events for Child Objects" option (a little button next to the "Event" list) and then to select objects that are not fragments in the hierarchy.  The Script Editor should then show only events for the selected object, and since it is not a fragment, there should be no problems with read-only mode.

Sorry for the difficulty.

Stephanie

Avatar

Avatar

pguerett

Avatar

pguerett

pguerett

28-05-2009

I don't think it is the resizing of the window ....I am constantly doing that without issue. Did you copy and paste the commands from the forum?

I have had issues where  the forum puts extra chars in the string and the script editor cannot interpret them.

Paul

Avatar

Avatar

SciMax

Avatar

SciMax

SciMax

28-05-2009

Oops.... I'm showing my age eh? I'll have to come up with some fancy acronym to use instead. How does PDFCP sound? ( poor defenceless form completer person)

This worked perfectly (woo hoo)!

BTW: I just learned something else interesting -- when I expand the Script Editor window to allow for multi-line viewing I get that script error message and it won't let me enter anything into any event. However, if I only set the Editor to a single line -- it lets me enter my code!! Hah... should have know the engineers would figure a way around things eh?? Pretty tricky

Thanks so much for your help! ….b

Avatar

Avatar

pguerett

Avatar

pguerett

pguerett

28-05-2009

By using a term like Filler I know you have been doing this for some time. You woudl put the code on the initialize event of the root object in the hierarchy tree (probably form1). Then it is just a matter of getting the right path and name into the command. You can edit your fragment and on the field you want to get the expression from you can add this command on its Initialize event.

xfa.host.messageBox(this.somExpression)

This command will write a messageBox to the screen giving you the expression that you ned to use to represent the object. Once you have this remove this line of code and update the cursor code with the new object expression.

Paul

Avatar

Avatar

SciMax

Avatar

SciMax

SciMax

28-05-2009

Thanks Paul. Your explanation does make sense. This is fantastic information in understanding HOW it works -- not just that it works (my level of understanding <grin>)!

I attempted to apply your suggested script but I'm still not able to place it into the Script Editor in what I think is the appropriate object. I get the same warning message about fragments.

I've attached the XDP since I'm not good at explaining myself. What I'm trying to do is have the focus automatically go to the first field -- Department name -- that filler needs to start at.

Please don't snicker too loud at some of my scripting (lol). I come from an extensive background in forms development and only recently gotten into actual coding.

Thanks. ….b

Avatar

Avatar

pguerett

Avatar

pguerett

pguerett

27-05-2009

Your logic is correct but the execution is not. Acrobat (the application) owns the placement of the cursor. The objects that are created for your form do not exist in Acrobat until the form is loaded and the user has control. This means that any script to access those objects (through Acrobat) will error out saying the object does not exist before the user has control. So we have to issue the command in the future, after the form is loaded and the user has control. So if we put code on the docReady event (one of the last thing sto heappen before control is given to the user, we can ask Acrobat to run this command in x number of milliseconds

Note that this is an AcroForm command and we have to use the full name of the field to pass to the command. The string in between the quotes is a command on its own that will be executed 100 milliseconds after this command is executed. The "this" portion of the command refers to the doc object in Acrobat not the current object like we do in XFA.

Make sense?

Paul