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

How do I hide objects in all instances of a sub-form?

Avatar

Level 2

I have a list of objects in a sub-form.  They are hidden or made visible depending on the selection of a drop-down menu outside the sub-form.  It works correctly for the first instance, but objects that are supposed to remain hidden become visible in all subsequent instances of the sub-form.

How do I make the objects remain hidden in all instances of the sub-form?

5 Replies

Avatar

Level 10

Hi,

The objects you add to your form get their properties from the template model, the properties you update in your code are in the form model.  So you will need to execute your code every time you add a new one.  This can be done in the calculate event of the subform and then it will also react to any changes in the drop down.

So, something like this JavaScript in the calculate event of the subform (which uses a checkbox that is ourside of subform and hides or shows TextField2)

if (CheckBox1.rawValue == 1)

{

    TextField2.presence = "hidden";

}

else

{

    TextField2.presence = "visible";

}

Regards

Bruce

Avatar

Level 2

Bruce,

The drop-down menu, not a checkbox, is in the header of the form.  It contains approximately 10 values, each of which drives the presence of objects, not TextField2, in the Bottom_of_Form subform.  Are you saying that I would have to put your script in approximately 100 places within my form for it to work correctly?

Avatar

Level 10

Hi,

Maybe I am not understanding your problem.  Is Bottom_of_Form the name of the subform that is repeating?  If so this is were I am suggesting you put the code based on the sample above, into the calculate event.  This code will need to handle the values of your drop down making the fields visible or hidden as required. 

The code sample above was just meant to show you the approach to use, it was not meant to be a implementation of the solution (this is a reasonable common question and the first time I answered it they were using a checkbox).

I you need more help then we will need to see you form, so we can customise the code to your form structure.

Regards

Bruce

Avatar

Level 2

My file is at https://www.dropbox.com/s/jr9yzsxrkvqenp5/EXP%20Sample%20Form.pdf

  1. On the drop-down selection box to select the "Plan", select the first entry on the list.
  2. Select the "New Contract" radio button for Request Type.
  3. Select ther "PCP" radio button for Provider Type
  4. Notice that there is a hole in the list where 3 objects are hidden.
  5. Click on "Add Additional Provider" button.
  6. Select "PCP" again.
  7. Notice that the 3 lines appear in the form, instead of staying hidden.

How do I keep them from popping up when I add Providers?

Avatar

Level 10

I think you want to move all the code from the change event of form1.EXP_Sample_Form.Identifier.Who.LOB_List.LOB_List to the calculate event of form1.EXP_Sample_Form.Bottom_of_Form. 

Which would then look like;

switch (Identifier.Who.LOB_List.LOB_List.rawValue)

{

    case "AmeriHealth Caritas":

        PCPInfo.Docs.SiteVisit.presence = "hidden";

        PCPInfo.Docs.Comments_SiteVisit.presence = "hidden";

        PCPInfo.Docs.SiteVisit_Received.presence = "hidden";

       

        PCPInfo.Docs.PanelAttestation.presence = "hidden";

        PCPInfo.Docs.Comments_PanelAttestation.presence = "hidden";

        PCPInfo.Docs.PanelAttestation_Received.presence = "hidden";

        break;

}

Here is your form with this suggestion made, https://workspaces.acrobat.com/?d=koCEYxi-59F7n5iyIoMhGQ

Bruce