Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Change subform presence based on pageCount?

Avatar

Level 2

I am losing my mind here! There's got to be a way to do this:

Trying to restrict the total number of pages in a dynamic form with a repeating subform.

  • The "Restrict Page Occurrence" option on the Master Page object tab does not work properly because of the repeating subform in the form.
  • I have two master pages. MasterPage1 is the first page of the document and MasterPage2 is pages 2+.
  • The form starts off as 1 page and if the user creates a few instances of the repeating subform, it'll automatically flow onto master page #2.
  • I created two buttons at the end of the form, each within their own subforms.
    • subform1.SubmitButton1 the actual Submit button and its presence should be "visible" if the total document page count is equal to or less than 3.
    • subform2.SubmitButton2 is a fake submit button set up with an error message on its click event and its presence should be set to "visible" if the total document page count is greater than 3 (it should be hidden otherwise).

I cannot for the life of me get the presence of these subforms to work! I'm not sure if I put code on the PageCount item on master page #2, or on the subform1 and subform2... 

Here's what I was trying:

if (xfa.layout.pageCount>3){

     Page1.subform1.SubmitButton1.presence = "hidden";

     Page1.subform2.SubmitButton2.presence = "visible";

} else {

     Page1.subform1.SubmitButton1.presence = "visible";   

     Page1.subform2.SubmitButton2.presence = "hidden";  

    }

Where am I going wrong? Thanks for any help you can provide!

1 Accepted Solution

Avatar

Correct answer by
Level 2

I figured it out! Here was the solution:

I wrapped my two buttons (Submit and fake submit) in a subform called "buttons". (Without wrapping them in the subform the functionality still worked but the buttons ended up at the top of page 1 instead of at the end of the form.)

Then I put this Javascript in the layout:ready event of SubmitButton1 (the real submit button):

if (xfa.layout.pageCount()>3) {

  Page1.buttons.SubmitButton1.presence = "hidden";

}

else {

  Page1.buttons.SubmitButton1.presence = "visible";

}

And I put this Javascript in the layout:ready event of SubmitButton2 (the fake submit button):

if (xfa.layout.pageCount()>3) {

  Page1.buttons.SubmitButton2.presence = "visible";

}

else {

  Page1.buttons.SubmitButton2.presence = "hidden";

}

The presence of both buttons is set to "Hidden" in the Object - Field tab.

On the click event of SubmitButton2 I have this JavaScript:

 

xfa.host.messageBox("Per the instructions on page 1 of this form, this document must be no longer than 3 pages. Please delete some text from the document before you submit it so that it is 3 pages or less or else it will be rejected."

, "Exceeded Allowed Number of Pages", 1);

View solution in original post

1 Reply

Avatar

Correct answer by
Level 2

I figured it out! Here was the solution:

I wrapped my two buttons (Submit and fake submit) in a subform called "buttons". (Without wrapping them in the subform the functionality still worked but the buttons ended up at the top of page 1 instead of at the end of the form.)

Then I put this Javascript in the layout:ready event of SubmitButton1 (the real submit button):

if (xfa.layout.pageCount()>3) {

  Page1.buttons.SubmitButton1.presence = "hidden";

}

else {

  Page1.buttons.SubmitButton1.presence = "visible";

}

And I put this Javascript in the layout:ready event of SubmitButton2 (the fake submit button):

if (xfa.layout.pageCount()>3) {

  Page1.buttons.SubmitButton2.presence = "visible";

}

else {

  Page1.buttons.SubmitButton2.presence = "hidden";

}

The presence of both buttons is set to "Hidden" in the Object - Field tab.

On the click event of SubmitButton2 I have this JavaScript:

 

xfa.host.messageBox("Per the instructions on page 1 of this form, this document must be no longer than 3 pages. Please delete some text from the document before you submit it so that it is 3 pages or less or else it will be rejected."

, "Exceeded Allowed Number of Pages", 1);