Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

Show / Hide Pages from DropDownList Selection

Avatar

Level 4

I am trying to Show / Hide the final page of an audit report depending on what town is selected from the drop down box.

The code that I'm using is :

if

("4" == xfa.event.newText)

{

Page7.presence

= "visible";

}

Page 7 is set to "hidden" as I only want it to show / print if certain towns are selected (Bundaberg being one of them)

The drop down box has had the Values set so "4" = Bundaberg.   The scripting is on a change event.

Can someone please help as this code isn't working.

Thanks.

Jenny

1 Accepted Solution

Avatar

Correct answer by
Level 10

Check that form is saved as 'Dynamic'.

N.

View solution in original post

31 Replies

Avatar

Level 10

May be any of the below reasons..

1) Check the Subform Name is actually Page7..

In the Heirarchy it looks like Page7 but if you see in the Binding Tab under Properties section it may be blank. If you do not see Page7 in the properties enter Page7 in properties.

Subform Name.JPG

2) Try this in the Exit event..

if(this.rawValue == "4"){

     Page7.presence = "visible";

}

Thanks

Srini

Avatar

Level 4

Hi Srini

Subform is Page7

I have tried your formula and it doesn't work.

Hidden.JPG

Avatar

Correct answer by
Level 10

Check that form is saved as 'Dynamic'.

N.

Avatar

Level 4

Morning Niall

It has been saved as a dynamic form.  This is what that has me stumpted.

Any other suggestion?

Jen

Avatar

Level 10

Hi Jen,

From your screenshot there is a dropdown in the Master page. Is this where the script is located?

I find that when referencing objects on the master page from objects on the design pages (and vice-versa) it is more robust to resolve the node.

so the script in the exit event of the dropdown may look like:

if (this.rawValue == "4")

{

     xfa.resolveNode("form1.Page7").presence = "visible";

}

else

{

     xfa.resolveNode("form1.Page7").presence = "hidden";

}

Next have a look at the pagination for Page7, it should be set to 'Follow previous'.

Hope that helps,

Niall

Sorry, my mistake, I now see that the dropdown I was referring to is on Page1.

Avatar

Level 4

Morning,

I have used your code but I still can't get it to work.  Is there an e-mail that I can send it through to you so you can have a look at the whole doc?

Jen

Avatar

Level 4

Morning Niall,

Thank you it works perfectly.

On a similar subject, I have a textfield that is hidden (exclude from layout) but I want it to print.  I have a 'Print' button on the Mater Page which I'm assuming will have some sort of scripting in it but I just don't know what that scripting would be.

Can you please assist with the scripting?

Regards

Jenny

Avatar

Level 10

Hi Jenny,

Do you really need the object Hidden, excluded from layout? This setting will allow other objects to take up the hidden objects space in a flowed form. If the from is positioned, then hidden does not have many advantages over invisible.

If that is the case, then instead of using hidden, you could use "Visible (print only)" setting in the Object > Field > Presence. This will automatically show the object on the printed page only.

There is a script approach (relevant) that should work irrespective of the objects visibility:

textField1.relevant = "+print";

However I find this flakey at the best of times.

Niall

Avatar

Level 4

Hi Niall,

It is a pop-up screen, when you 'mouseenter' over another button it pop-ups and shows legend / examples and when you when you 'mouseexit' it disappears.  The print button is for printing the legend only.

So my scripting for my particular example would be legend.relevant = "+print";

I understand that this is flakey but is there anything else?

Jen

Avatar

Level 10

Hi Jen,

Based on both threads, I have done up a sample here: https://acrobat.com/#d=55NDY8upAYilzRV*8fmLVA

The .relevance method won't help you here, because you only want the legend to print when a specific button is pressed. If the user hits the general print button or the File > Print, you do not want the legend to print.

The sample shows/hides the form elements and I think is what you are after.

Hope that helps,

Niall

Avatar

Level 4

Hi Niall,

I have nearly got it.  I just can't get the legend to print out - it prints out a blank page.

This is what I have......

Print1.JPG

Print.JPG

Print2.JPG

Avatar

Level 10

Hi Jen,

A couple of things:

The line:

form1.presence = "hidden"; 

will hide the whole form.

Because the thing you want to be visible is on page2, BOTH form1 and page2 must be visible. I would be inclined to hide page1, Subform2 (on page2) and page3.

I think this is the main problem with the form. To display the legend the following elements must be visible:

  • form1
  • page2
  • subform1 (on page2), otherwise the button with the script will disappear
  • subform2 (on page2)

A couple of very minor points (nothing to do with the problem):

  • Javascript syntax requires a semi-colon (;) at the end of each line. But FormCalc does not need it, so you can drop it in your script.
  • I would name objects as you are going, eg the various buttons.
  • I would be inclined to give the subforms different names.

Let me know how you get on.

Niall

Avatar

Level 4

Hi Niall,

When I go to print the screen on the print menu is blank until I select page 2 and the legend shows on the print menu.

When I actually print it out it prints a blank page and the footter says 1 of 2 and there is no 2 of 2.

How do I get rid of the first blank screen.

This is the coding that I have used on the 'click event'

Page1.presence

= "hidden"

Page2.Subform1.presence

= "hidden"

Page2.Subform2.legend.presence

= "visible"

Page2.Subform2.Subform1.presence

= "hidden"

Page2.Subform2.Subform2.presence

= "hidden"

Page3.presence

= "hidden"

xfa.host.print(1, "0", "0", 0, 0, 0,0, 0)

Can I 'hide' the mater page?

Cheers,

Jenny

Avatar

Level 10

Hi Jenny,

The xfa.host.print script is set to print the first visible page. This is from the second and third parameters of the command. The pages are numbers on a zero basis, so in both parameters "0" means the first visible page.

So I suspect that the pagination settings are slightly out. The script is hiding page1, but the pagination is keeping the page there, albeit with no content. Then the print script is printing the blank page.

So if you select each page in turn and check the Object > Pagination settings, they should all look like this:

Parallels Desktop1.png

Hope that gets it working. If not you could email me the form and I will have a look at it.

Niall

Avatar

Level 4

One little issue left, once I have printed the page, the curser goes back to the beginning of the doc.  How do I get around this?

Jen

Avatar

Level 10

Hi Jen,

You could add script to the end of the script block:

xfa.host.currentPage = 1;

This would go to page 2, because the page numbers are zero based.

Hope that clinches it for you.

Niall

Avatar

Level 4

I put the coding on the postPrint but it doesn't work.  I still get taken back to first page.

Avatar

Level 10

Hi Jen,

Try and make sure that it comes after the script that shows page1 again.

If that doesn't work, try the setFocus property and set it to a field on page2 (eg 'myTextField').

xfa.host.setFocus(xfa.form.form1.Page2.myTextField);

Check the SOM reference in the script. Hopefully that will get it,
Niall

Avatar

Level 4

form1.Page2.Subform1.#field[0]::click - (JavaScript, client)

Page1.presence

= "hidden";

Page2.Subform1.presence

= "hidden";

Page2.Subform2.legend.presence

= "visible";

Page2.Subform2.Subform1.presence

= "hidden";

Page2.Subform2.Subform2.presence

= "hidden";

Page3.presence

= "hidden";

Page5.presence

= "hidden";

Page6.presence

= "hidden";

Page7.presence

= "hidden";

xfa.host.print(1

, "0", "0", 0, 0, 0,0, 0);

form1.Page2.Subform1.#field[0]::postPrint - (JavaScript, client)

Page1.presence

= "visible";

Page2.Subform1.presence

= "visible";

Page2.Subform2.legend.presence

= "hidden";

Page2.Subform2.Subform1.presence

= "visible";

Page2.Subform2.Subform2.presence

= "visible";

Page3.presence

= "visible";

Page5.presence

= "visible";

Page6.presence

= "visible";

Page7.presence

= "visible";

xfa.host.setFocus(xfa.form.form1.Page2.Subform1.Text12);     

form1.Page2.Subform1.#field[0]::mouseEnter - (JavaScript, client)

Subform2.legend.presence

= "visible";

form1.Page2.Subform1.#field[0]::mouseExit - (JavaScript, client)

Subform2.legend.presence

= "hidden";

I don't understand what a SOM reference in the script is?