Expand my Community achievements bar.

Problem using xfa.host.currentPage

Avatar

Former Community Member
I'm working on a dynamic form with eight different pages (as subforms). When you open the form only two pages are visible, the others are hidden. After the user clicks on a button a new page gets added (visible) to the form. Now I want the new page to become the current page. I tried to set xfa.host.currentPage to the new page in layout:ready event for the new page. But at this point the Host Model doesn't know about the new page (xfa.host.numPages has still value 2), so I have no chance to set xfa.host.currentPage to 3. The Layout Model knows the new page already (xfa.layout.pageCount has value 3).



Do you have any idea at which point I might be able to set xfa.host.currentPage to the new page?



Thanks for your help!
19 Replies

Avatar

Former Community Member
Can you post a link to your form? I had a problem similar to that a while back.

Avatar

Former Community Member
Hi Nick,



unfortunately I'm not able to post a link to my form. Do you think you can help me without having seen the form? Do you understand my problem or do you need more information?



Thanks,

Andrea

Avatar

Former Community Member
Without looking at your code, I'd be chasing my own tail. Go ahead and email it to me at box71996-temp@yahoo.com.

Avatar

Former Community Member
There is not really code I could send to you, because everything I tried didn't work.



To keep the problem simple I try to give you a better description of what I want to do:



Take a form with two pages. The first one is visible, the second is hidden. Put a button on the first page and one textfield on the second. Put a script on the click event of the button to set "presence" of the second page to "visible" and "relevant" to "print".



Open the form with Adobe Acrobat Professional. Only the first page should be visible. Click the button, the second page gets added to the form, but the focus still remains on the first page.

When clicking the button, I want the second page to become visible and the textfield on the second page to get the focus. But I couldn't figure out what type of event gets fired as soon as the new page gets added to the form.



I tried to set xfa.host.currentPage to the second page and xfa.host.setFocus to the textfield in layout:ready event for the second page. But when layout:ready gets fired the Host Model doesn't know about the second page (xfa.host.numPages has still value 1), so I have no chance to set xfa.host.currentPage to 2. The Layout Model knows the new page already (xfa.layout.pageCount has value 2).



I also tried to fire "enter"-event to the second page in layout:ready, but it didn't work as well.



For me it seems like trying to set current page or focus inside layout:ready is not the correct way, but I don't know when I'll be able to set the focus on the new page.

Avatar

Former Community Member
Hi Andrea,



There is a bug preventing you to achieve this behavior.



There is no pretty workaround I can think of.



Hélène

Adobe Systems Inc.

Avatar

Former Community Member
Thanks for the information.



Is there any fix or workaround coming up?

Avatar

Former Community Member
Good morning Andrea,



Good news. There is a workaround!



Set the current page after a time out. This will give enough time for the host to become aware of the new page.



app.setTimeOut("xfa.host.currentPage=1", 10);



Hope this helps,

Hélène



Adobe Systems Inc.

Avatar

Former Community Member
Thanks for the information - it works!



But the next question is, how to set the focus to the text field on the second page? Neiter xfa.host.setFocus("xfa.form.form1.page2.TextField"); nor app.setTimeOut("xfa.host.setFocus("xfa.form.form1.page2.TextField")", 10); sets the focus to the text field. Any idea how to fix this?



Greetings, Andrea

Avatar

Former Community Member
Try



app.setTimeOut("this.getField('form1[0].s1[0].TextField2[0]').setFocus()", 50);



Cheers



Hélène

Adobe Systems Inc

Avatar

Former Community Member
...sorry, wrong SOM expression...



Try



app.setTimeOut("this.getField('form1[0].page2[0].TextField[0]').setFocus()", 50);

Avatar

Former Community Member
Wow, I'm too quick on the submit today!



A time out of 10 milliseconds is enough.



Hélène

Adobe Systems Inc

Avatar

Former Community Member
Hi Helene,



thanks for your information. It works quite well for my little example form, but unfortunately not for my originally eight pages form even if I set the timeout to 5000. Neither trying to set current page nor trying to set focus. Any ideas?



In my opinion it's not good style to use a timeout for setting a new current page or for setting the focus. It would be much better to throw an event as soon as the host knows about the new page.

Avatar

Former Community Member
Andrea,



Yes you are right, this is not good style. But keep in mind there is a bug and this is a workaround.



Also, it is not good style to change the presence of a subform. Instead, use the subform's instance manager to add, remove, move, set, and insert subform instances.



Back to you question. Is your form dynamic? The layout will not be updated if you preview the form as a static PDF. Also, when you preview the form, start the JavaScript Debugger. It will help debug scripting errors. Press CTRL+J.



Hélène

Adobe Systems Inc

Avatar

Former Community Member
Hi Helene,



thanks for the hint to use the subform's instance manager.

Do you think there won't be a timing problem when using the instance manager instead of changing the presence of a subform?



I'm really wondering why the workaround you recommended is working for my little sample form but not for my originally one.

My form is dynamic and I'm previewing the form as dynamic PDF (the sample and the originally form). Also I'm using the JavaScript Debugger already, which doesn't show any errors.



I'm thinking about stripping my eight pages form to see at what point the workaround is not working anymore.

Or do you have any other ideas? Should I change my form to use the subform's instance manager? Will there be a fix for the timing bug avaible soon?

Avatar

Former Community Member
Helene,



I've finally found out why the originally form is not doing well when using your workaround.



The originally form contains a paper form barcode. When eliminating everything belonging to the paper form barcode the timeout-call is working perfectly (the correct page and field gains the focus). As soon as the paper form barcode is added to the form, the timeout is not working anymore.



Now my problem is: how can I get both to work (paper form barcode and setting the focus)?

Avatar

Former Community Member
Hi Andrea,



I have a similar problem, but I can't get the first part to work eighter. The first part I am referring to is making a page invisible initially and then make it available on a click of a button.

When ever I make a page invisible, in the PDF preview, I still see two pages but all the objects on the second page are invisible.

How did you make the complete page invisible?

Avatar

Former Community Member
Hi Vikram,



in the object palette of your subform you have to set "Presence" to "Hidden (Exclude from Layout)".

Avatar

Former Community Member
Thanks, I did not wrap the page in subform and page does not have any presence property.

Avatar

Former Community Member
Helene,



You said that is it not good style to use the presence property with subforms and the instance manager should be used instead.



Does this rule apply only when a subform is repeated? Or does it apply to all subforms?



I have eight different subforms with difference content that need to be visible/created and hidden/deleted at various events and I have been using the presence property so far to achieve this.



Is this bad practice?